|
2 | 2 | <#
|
3 | 3 | .SYNOPSIS
|
4 | 4 | Deploys an existing DBOps package
|
5 |
| - |
| 5 | +
|
6 | 6 | .DESCRIPTION
|
7 | 7 | Deploys an existing DBOps package with optional parameters.
|
8 | 8 | Uses a table specified in SchemaVersionTable parameter to determine scripts to run.
|
9 | 9 | Will deploy all the builds from the package that previously have not been deployed.
|
10 |
| - |
| 10 | +
|
11 | 11 | .PARAMETER Path
|
12 | 12 | Path to the existing DBOpsPackage.
|
13 | 13 | Aliases: Name, FileName, Package
|
14 | 14 |
|
15 | 15 | .PARAMETER InputObject
|
16 | 16 | Pipeline implementation of Path. Can also contain a DBOpsPackage object.
|
17 |
| - |
| 17 | +
|
18 | 18 | .PARAMETER SqlInstance
|
19 | 19 | Database server to connect to. SQL Server only for now.
|
20 | 20 | Aliases: Server, SQLServer, DBServer, Instance
|
21 |
| - |
| 21 | +
|
22 | 22 | .PARAMETER Database
|
23 | 23 | Name of the database to execute the scripts in. Optional - will use default database if not specified.
|
24 |
| - |
| 24 | +
|
25 | 25 | .PARAMETER DeploymentMethod
|
26 | 26 | Choose one of the following deployment methods:
|
27 | 27 | - SingleTransaction: wrap all the deployment scripts into a single transaction and rollback whole deployment on error
|
28 | 28 | - TransactionPerScript: wrap each script into a separate transaction; rollback single script deployment in case of error
|
29 | 29 | - NoTransaction: deploy as is
|
30 |
| - |
| 30 | +
|
31 | 31 | Default: NoTransaction
|
32 |
| - |
| 32 | +
|
33 | 33 | .PARAMETER ConnectionTimeout
|
34 | 34 | Database server connection timeout in seconds. Only affects connection attempts. Does not affect execution timeout.
|
35 | 35 | If 0, will wait for connection until the end of times.
|
36 |
| - |
| 36 | +
|
37 | 37 | Default: 30
|
38 |
| - |
| 38 | +
|
39 | 39 | .PARAMETER ExecutionTimeout
|
40 | 40 | Script execution timeout. The script will be aborted if the execution takes more than specified number of seconds.
|
41 | 41 | If 0, the script is allowed to run until the end of times.
|
42 | 42 |
|
43 | 43 | Default: 0
|
44 |
| - |
| 44 | +
|
45 | 45 | .PARAMETER Encrypt
|
46 | 46 | Enables connection encryption.
|
47 |
| - |
| 47 | +
|
48 | 48 | .PARAMETER Credential
|
49 | 49 | PSCredential object with username and password to login to the database server.
|
50 |
| - |
| 50 | +
|
51 | 51 | .PARAMETER UserName
|
52 | 52 | An alternative to -Credential - specify username explicitly
|
53 |
| - |
| 53 | +
|
54 | 54 | .PARAMETER Password
|
55 | 55 | An alternative to -Credential - specify password explicitly
|
56 |
| - |
| 56 | +
|
57 | 57 | .PARAMETER SchemaVersionTable
|
58 | 58 | A table that will hold the history of script execution. This table is used to choose what scripts are going to be
|
59 | 59 | run during the deployment, preventing the scripts from being execured twice.
|
60 | 60 | If set to $null, the deployment will not be tracked in the database. That will also mean that all the scripts
|
61 | 61 | and all the builds from the package are going to be deployed regardless of any previous deployment history.
|
62 | 62 |
|
63 | 63 | Default: SchemaVersions
|
64 |
| - |
| 64 | +
|
65 | 65 | .PARAMETER Silent
|
66 | 66 | Will supress all output from the command.
|
67 |
| - |
| 67 | +
|
68 | 68 | .PARAMETER Variables
|
69 | 69 | Hashtable with variables that can be used inside the scripts and deployment parameters.
|
70 | 70 | Proper format of the variable tokens is #{MyVariableName}
|
71 | 71 | Can also be provided as a part of Configuration hashtable: -Configuration @{ Variables = @{ Var1 = ...; Var2 = ...}}
|
72 | 72 | Will augment and/or overwrite Variables defined inside the package.
|
73 |
| - |
| 73 | +
|
74 | 74 | .PARAMETER OutputFile
|
75 | 75 | Log output into specified file.
|
76 |
| - |
| 76 | +
|
77 | 77 | .PARAMETER Append
|
78 | 78 | Append output to the -OutputFile instead of overwriting it.
|
79 | 79 |
|
80 | 80 | .PARAMETER ConnectionString
|
81 | 81 | Custom connection string that will override other connection parameters.
|
82 | 82 | IMPORTANT: Will also ignore user/password/credential parameters, so make sure to include proper authentication credentials into the string.
|
83 |
| - |
| 83 | +
|
84 | 84 | .PARAMETER Configuration
|
85 | 85 | A custom configuration that will be used during a deployment, overriding existing parameters inside the package.
|
86 | 86 | Can be a Hashtable, a DBOpsConfig object, or a path to a json file.
|
|
90 | 90 |
|
91 | 91 | .PARAMETER Build
|
92 | 92 | Only deploy certain builds from the package.
|
93 |
| - |
| 93 | +
|
94 | 94 | .PARAMETER CreateDatabase
|
95 | 95 | Will create an empty database if missing on supported RDMBS
|
96 | 96 |
|
97 | 97 | .PARAMETER ConnectionType
|
98 | 98 | Defines the driver to use when connecting to the database server.
|
99 | 99 | Available options: SqlServer (default), Oracle
|
100 |
| - |
| 100 | +
|
101 | 101 | .PARAMETER Confirm
|
102 | 102 | Prompts to confirm certain actions
|
103 | 103 |
|
|
107 | 107 | .EXAMPLE
|
108 | 108 | # Installs package with predefined configuration inside the package
|
109 | 109 | Install-DBOPackage .\MyPackage.zip
|
110 |
| - |
| 110 | +
|
111 | 111 | .EXAMPLE
|
112 | 112 | # Installs package using specific connection parameters
|
113 | 113 | .\MyPackage.zip | Install-DBOPackage -SqlInstance 'myserver\instance1' -Database 'MyDb' -ExecutionTimeout 3600
|
114 |
| - |
| 114 | +
|
115 | 115 | .EXAMPLE
|
116 | 116 | # Installs package using custom logging parameters and schema tracking table
|
117 | 117 | .\MyPackage.zip | Install-DBOPackage -SchemaVersionTable dbo.SchemaHistory -OutputFile .\out.log -Append
|
|
170 | 170 | [Alias('Type', 'ServerType')]
|
171 | 171 | [string]$ConnectionType = 'SQLServer'
|
172 | 172 | )
|
173 |
| - |
| 173 | + |
174 | 174 | begin {
|
175 | 175 | }
|
176 | 176 | process {
|
|
187 | 187 | #Merging the custom configuration provided
|
188 | 188 | $config = $config | Get-DBOConfig -Configuration $Configuration
|
189 | 189 |
|
190 |
| - #Merge custom parameters into the configuration, excluding variables |
| 190 | + #Merge custom parameters into a configuration |
| 191 | + $newConfig = @{} |
191 | 192 | foreach ($key in ($PSBoundParameters.Keys)) {
|
192 |
| - if ($key -in [DBOpsConfig]::EnumProperties() -and $key -ne 'Variables') { |
| 193 | + if ($key -in [DBOpsConfig]::EnumProperties()) { |
193 | 194 | Write-PSFMessage -Level Debug -Message "Overriding parameter $key with $($PSBoundParameters[$key])"
|
194 |
| - $config.SetValue($key, $PSBoundParameters[$key]) |
| 195 | + $newConfig.$key = $PSBoundParameters[$key] |
195 | 196 | }
|
196 | 197 | }
|
197 |
| - |
| 198 | + $config.Merge($newConfig) |
| 199 | + |
198 | 200 | #Prepare deployment function call parameters
|
199 | 201 | $params = @{
|
200 |
| - InputObject = $package |
| 202 | + InputObject = $package |
201 | 203 | Configuration = $config
|
202 | 204 | }
|
203 | 205 | foreach ($key in ($PSBoundParameters.Keys)) {
|
204 | 206 | #If any custom properties were specified
|
205 |
| - if ($key -in @('OutputFile', 'Append', 'Variables', 'ConnectionType', 'Build')) { |
| 207 | + if ($key -in @('OutputFile', 'Append', 'ConnectionType', 'Build')) { |
206 | 208 | $params += @{ $key = $PSBoundParameters[$key] }
|
207 | 209 | }
|
208 | 210 | }
|
209 | 211 | Write-PSFMessage -Level Verbose -Message "Preparing to start the deployment of package $($package.FileName)"
|
210 | 212 | Invoke-DBODeployment @params
|
211 | 213 | }
|
212 | 214 | end {
|
213 |
| - |
| 215 | + |
214 | 216 | }
|
215 | 217 | }
|
0 commit comments