Advertisement
Guest User

Untitled

a guest
Dec 6th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.97 KB | None | 0 0
  1. #Package location variables
  2. $filename = $OctopusParameters['Octopus.Action[Deploy Nuget Package].Package.NuGetPackageId']
  3. $fileversion = $OctopusParameters['Octopus.Action[Deploy Nuget Package].Package.NuGetPackageVersion']
  4.  
  5. #Connection Variables
  6. #Set Target DB Name for Auto Deployment
  7. if ($TargetDatabaseName -eq "") {
  8. $TargetDatabaseName = "$filename.$fileversion"
  9. }
  10.  
  11. #Required for DB Versioning
  12. $version = "$filename.$fileversion"
  13. $release = $OctopusParameters['Octopus.Release.Number']
  14. $user = $OctopusParameters['Octopus.Deployment.CreatedBy.Username']
  15.  
  16. #Get list of files
  17. $files = Get-Childitem "$ExtractLocation\dbo\Scripts\Deployment\TestData\Item.sql",
  18. "$ExtractLocation\dbo\Scripts\Deployment\TestData\PriceBand.sql",
  19. "$ExtractLocation\dbo\Scripts\Deployment\TestData\PriceClass.sql",
  20. "$ExtractLocation\dbo\Scripts\Deployment\TestData\Block.sql",
  21. "$ExtractLocation\dbo\Scripts\Deployment\TestData\CRC.sql",
  22. "$ExtractLocation\dbo\Scripts\Deployment\TestData\Entrance.sql",
  23. "$ExtractLocation\dbo\Scripts\Deployment\TestData\GlobalSetting.sql",
  24. "$ExtractLocation\dbo\Scripts\Deployment\TestData\InetConfig.sql",
  25. "$ExtractLocation\dbo\Scripts\Deployment\TestData\MemberPriceClass.sql",
  26. "$ExtractLocation\dbo\Scripts\Deployment\TestData\Password.sql",
  27. "$ExtractLocation\dbo\Scripts\Deployment\TestData\PRC.sql",
  28. "$ExtractLocation\dbo\Scripts\Deployment\TestData\Client.sql",
  29. "$ExtractLocation\dbo\Scripts\Deployment\TestData\License.sql",
  30. "$ExtractLocation\dbo\Scripts\Deployment\TestData\Venue.sql",
  31. "$ExtractLocation\dbo\Scripts\Deployment\TestData\Auditorium.sql",
  32. "$ExtractLocation\dbo\Scripts\Deployment\TestData\Layout.sql",
  33. "$ExtractLocation\dbo\Scripts\Deployment\TestData\Production.sql",
  34. "$ExtractLocation\dbo\Scripts\Deployment\TestData\EventType.sql",
  35. "$ExtractLocation\dbo\Scripts\Deployment\TestData\Charge.sql",
  36. "$ExtractLocation\dbo\Scripts\Deployment\TestData\Event.sql",
  37. "$ExtractLocation\dbo\Scripts\Deployment\TestData\Tlog.sql",
  38. "$ExtractLocation\dbo\Scripts\Deployment\TestData\MemberType.sql",
  39. "$ExtractLocation\dbo\Scripts\Deployment\TestData\EventMemberTypeLink.sql",
  40. "$ExtractLocation\dbo\Scripts\Deployment\TestData\ClientType.sql",
  41. "$ExtractLocation\dbo\Scripts\Deployment\TestData\ClientTypeLink.sql",
  42. "$ExtractLocation\dbo\Scripts\Deployment\TestData\Price.sql",
  43. "$ExtractLocation\dbo\Scripts\Deployment\TestData\PriceClassClientTypeLink.sql",
  44. "$ExtractLocation\dbo\Scripts\Deployment\TestData\PriceClassMembershipLink.sql",
  45. "$ExtractLocation\dbo\Scripts\Deployment\TestData\Member.sql",
  46. "$ExtractLocation\dbo\Scripts\Deployment\TestData\SeasonGroup.sql",
  47. "$ExtractLocation\dbo\Scripts\Deployment\TestData\MemberPrice.sql",
  48. "$ExtractLocation\dbo\Scripts\Deployment\TestData\MTlog.sql",
  49. "$ExtractLocation\dbo\Scripts\Deployment\TestData\Card.sql",
  50. "$ExtractLocation\dbo\Scripts\Deployment\TestData\DirectDebit.sql",
  51. "$ExtractLocation\dbo\Scripts\Deployment\TestData\Booking.sql",
  52. "$ExtractLocation\dbo\Scripts\Deployment\TestData\Payment.sql",
  53. "$ExtractLocation\dbo\Scripts\Deployment\TestData\BookingPayLink.sql",
  54. "$ExtractLocation\dbo\Scripts\Deployment\TestData\ProdSGLink.sql",
  55. "$ExtractLocation\dbo\Scripts\Deployment\TestData\MemHistory.sql",
  56. "$ExtractLocation\dbo\Scripts\Deployment\TestData\MemHPayLink.sql",
  57. "$ExtractLocation\dbo\Scripts\Deployment\TestData\PaymentProfile.sql",
  58. "$ExtractLocation\dbo\Scripts\Deployment\TestData\Finance.sql",
  59. "$ExtractLocation\dbo\Scripts\Deployment\TestData\SGEventLink.sql",
  60. "$ExtractLocation\dbo\Scripts\Deployment\TestData\TXEvent.sql",
  61. "$ExtractLocation\dbo\Scripts\Deployment\TestData\ChargeProfileType.sql",
  62. "$ExtractLocation\dbo\Scripts\Deployment\TestData\ChargeProfile.sql",
  63. "$ExtractLocation\dbo\Scripts\Deployment\TestData\ChargeCategory.sql",
  64. "$ExtractLocation\dbo\Scripts\Deployment\TestData\InetPriceBand.sql",
  65. "$ExtractLocation\dbo\Scripts\Deployment\TestData\InetPriceClass.sql",
  66. "$ExtractLocation\dbo\Scripts\Deployment\TestData\PackageX.sql",
  67. "$ExtractLocation\dbo\Scripts\Deployment\TestData\PackageXEventPriceClassLink.sql",
  68. "$ExtractLocation\dbo\Scripts\Deployment\TestData\Area.sql",
  69. "$ExtractLocation\dbo\Scripts\Deployment\TestData\RowName.sql",
  70. "$ExtractLocation\dbo\Scripts\Deployment\TestData\ItemTag.sql",
  71. "$ExtractLocation\dbo\Scripts\Deployment\TestData\ItemTagLink.sql",
  72. "$ExtractLocation\dbo\Scripts\Deployment\TestData\BestAvailArea.sql",
  73. "$ExtractLocation\dbo\Scripts\Deployment\TestData\ClientRatio.sql",
  74. "$ExtractLocation\dbo\Scripts\Deployment\TestData\ClientUpdateHistory.sql",
  75. "$ExtractLocation\dbo\Scripts\Deployment\TestData\InetTransaction.sql",
  76. "$ExtractLocation\dbo\Scripts\Deployment\TestData\PanViewLog.sql",
  77. "$ExtractLocation\dbo\Scripts\Deployment\TestData\Permission.sql",
  78. "$ExtractLocation\dbo\Scripts\Deployment\TestData\RptPayment.sql",
  79. "$ExtractLocation\dbo\Scripts\Deployment\TestData\UpsellItem.sql",
  80. "$ExtractLocation\dbo\Scripts\Deployment\TestData\UpsellPollerLog.sql",
  81. "$ExtractLocation\dbo\Scripts\Deployment\TestData\UsageTracking.sql",
  82. "$ExtractLocation\dbo\Scripts\Deployment\TestData\UsageTrackingGS.sql",
  83. "$ExtractLocation\dbo\Scripts\Deployment\TestData\UsageTrackingPrt.sql",
  84. "$ExtractLocation\dbo\Scripts\Deployment\TestData\UsageTrackingSys.sql",
  85. "$ExtractLocation\dbo\Scripts\Deployment\TestData\UsageTrackingVMO.sql",
  86. "$ExtractLocation\dbo\Scripts\Deployment\TestData\UserLog.sql",
  87. "$ExtractLocation\dbo\Scripts\Deployment\TestData\VMOption.sql",
  88. "$ExtractLocation\dbo\Scripts\Deployment\TestData\VMPermList.sql",
  89. "$ExtractLocation\dbo\Scripts\Deployment\TestData\WSID.sql",
  90. "$ExtractLocation\dbo\Scripts\Deployment\TestData\SeatSkel.sql",
  91. "$ExtractLocation\dbo\Scripts\Deployment\TestData\Seat.sql",
  92. "$ExtractLocation\dbo\Scripts\Deployment\TestData\SeatHistory.sql",
  93. "$ExtractLocation\dbo\Scripts\Deployment\TestData\BookingChargeLink.sql",
  94. "$ExtractLocation\dbo\Scripts\Deployment\TestData\InetTransactionChargeProfileLink.sql",
  95. "$ExtractLocation\dbo\Scripts\Deployment\TestData\ContactHistory.sql",
  96. "$ExtractLocation\dbo\Scripts\Deployment\TestData\BallotRegrets.sql",
  97. "$ExtractLocation\dbo\Scripts\Deployment\TestData\DDInstall.sql",
  98. "$ExtractLocation\dbo\Scripts\Deployment\TestData\ClientLink.sql",
  99. "$ExtractLocation\dbo\Scripts\Deployment\TestData\InetBasket.sql",
  100. "$ExtractLocation\dbo\Scripts\Deployment\TestData\InetBasketChargeProfileLink.sql",
  101. "$ExtractLocation\dbo\Scripts\Deployment\TestData\InetBasketItem.sql",
  102. "$ExtractLocation\dbo\Scripts\Deployment\TestData\MemHChargeLink.sql",
  103. "$ExtractLocation\dbo\Scripts\Deployment\TestData\PaymentProfileInstalment.sql",
  104. "$ExtractLocation\dbo\Scripts\Deployment\TestData\SEPriceClassMapLink.sql",
  105. "$ExtractLocation\dbo\Scripts\Deployment\TestData\TMForward.sql",
  106. "$ExtractLocation\dbo\Scripts\Deployment\TestData\TMReceive.sql",
  107. "$ExtractLocation\dbo\Scripts\Deployment\TestData\TXTeamExchangeHistory.sql",
  108. "$ExtractLocation\dbo\Scripts\Deployment\TestData\DEKStore.sql",
  109. "$ExtractLocation\dbo\Scripts\Deployment\TestData\KEKStore.sql"
  110.  
  111. #Set GS key check SQL command
  112. $GScheck="IF EXISTS(SELECT 1 FROM dbo.GlobalSetting WHERE GS_name = 'G_TestDataDeployed')
  113. BEGIN
  114. SELECT 1 AS [Res];
  115. END;
  116. ELSE
  117. SELECT 0 AS [Res];"
  118.  
  119. #Set GS key insert SQL command
  120. $GSinsert="INSERT INTO dbo.GlobalSetting
  121. (
  122. GS_global,GS_wsid,GS_name,GS_value
  123. )
  124. VALUES (0, 0, N'G_TestDataDeployed', N'1');"
  125.  
  126. #Create a database connection
  127. $sqlConnection = new-object System.Data.SqlClient.SqlConnection "server=$server;database=$targetDatabaseName;Integrated Security = False; User ID = admin; Password = Stubbsgat3;"
  128.  
  129. try {
  130.  
  131. #Open SQL connection
  132. $SqlConnection.Open()
  133.  
  134. #Check for existence of GS key
  135. $sqlCheckGS = $sqlConnection.CreateCommand()
  136. $sqlCheckGS.CommandText = $GScheck
  137. $sqlCheckGS.Connection = $SqlConnection
  138. $GScheckResult = $sqlCheckGS.ExecuteScalar()
  139.  
  140. #Execute SQL if GS key is missing
  141. if($GScheckResult -ne $true) {
  142.  
  143. #Loop through each of the files in the test data
  144. foreach ($file in $files) {
  145.  
  146. $filename = $file.BaseName
  147. Write-Host "Currently deploying data to: "$filename
  148.  
  149. #Execute SQL files on db
  150. $sqlExecFile = $sqlConnection.CreateCommand()
  151. $sqlExecFile.CommandText = Get-Content $file
  152. #Set timeout value in seconds
  153. $sqlExecFile.CommandTimeout = 2100
  154. $sqlExecFile.Connection = $SqlConnection
  155. $sqlReader = $sqlExecFile.ExecuteReader()
  156. $sqlReader.Close()
  157.  
  158. }
  159.  
  160. #Add GS key to GlobalSetting
  161. $sqlInsertGS = $sqlConnection.CreateCommand()
  162. $sqlInsertGS.CommandText = $GSinsert
  163. $sqlInsertGS.Connection = $SqlConnection
  164. $sqlReader = $sqlInsertGS.ExecuteReader()
  165. $sqlReader.Close()
  166.  
  167. }
  168.  
  169. else {
  170.  
  171. Write-Host "Test data already deployed to $TargetDatabaseName"
  172.  
  173. }
  174.  
  175. #Close SQL connection
  176. $SqlConnection.Close()
  177.  
  178. }
  179.  
  180. catch {
  181.  
  182. #Close SQL connection
  183. $sqlReader.Close()
  184. $SqlConnection.Close()
  185. Write-Host "FAILED TO EXECUTE: " $filename
  186. throw
  187.  
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement