Skip to content

Commit 4208d44

Browse files
authored
Merge pull request #67 from sqlcollaborative/development
Packaging improvements and adding options to control script path handling
2 parents 7770981 + f437e97 commit 4208d44

33 files changed

+997
-1123
lines changed

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ for:
5353
- sudo -u postgres psql -c "CREATE USER sa WITH PASSWORD 'Password12!';"
5454
- sudo -u postgres psql -c "ALTER USER sa WITH SUPERUSER;"
5555
- ps: .\tests\appveyor.prep.ps1
56-
- docker run --name dbops-oracle -d -p 1521:1521 -e ORACLE_ALLOW_REMOTE=true wnameless/oracle-xe-11g
56+
# - docker run --name dbops-oracle -d -p 1521:1521 -e ORACLE_ALLOW_REMOTE=true wnameless/oracle-xe-11g
5757

5858
# before_test:
5959
# # run preparation scripts

functions/Add-DBOBuild.ps1

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ function Add-DBOBuild {
33
<#
44
.SYNOPSIS
55
Creates a new build in existing DBOps package
6-
6+
77
.DESCRIPTION
88
Creates a new build in existing DBOps package from specified set of scripts.
9-
9+
1010
.PARAMETER ScriptPath
1111
A collection of script files to add to the build. Accepts Get-Item/Get-ChildItem objects and wildcards.
1212
Will recursively add all of the subfolders inside folders. See examples if you want only custom files to be added.
1313
During deployment, scripts will be following this deployment order:
1414
- Item order provided in the ScriptPath parameter
1515
- Files inside each child folder (both folders and files in alphabetical order)
1616
- Files inside the root folder (in alphabetical order)
17-
17+
1818
Aliases: SourcePath
19-
19+
2020
.PARAMETER Path
2121
Path to the existing DBOpsPackage.
2222
Aliases: Name, FileName, Package
23-
23+
2424
.PARAMETER Build
2525
A string that would be representing a build number of this particular build.
2626
Optional - can be genarated automatically.
@@ -32,11 +32,24 @@ function Add-DBOBuild {
3232
* Modified: adds files only if they have been modified since they had last been added to the package
3333
* Unique: adds unique files to the build based on their hash values. Compares hashes accross the whole package
3434
* All: add all files regardless of their previous involvement
35-
35+
3636
More than one value can be specified at the same time.
37-
37+
3838
Default value: All
39-
39+
40+
.PARAMETER Absolute
41+
All the files in -Path will be added using their absolute paths instead of relative.
42+
43+
.PARAMETER Relative
44+
Use current location to build relative paths instead of starting from the folder in -Path.
45+
46+
.PARAMETER NoRecurse
47+
Only process the first level of the target -Path.
48+
49+
.PARAMETER Match
50+
Runs a regex verification against provided file names using the provided Match string.
51+
Example: .*\.sql
52+
4053
.PARAMETER Confirm
4154
Prompts to confirm certain actions
4255
@@ -72,20 +85,22 @@ function Add-DBOBuild {
7285
[object[]]$ScriptPath,
7386
[string]$Build,
7487
[ValidateSet('New', 'Modified', 'Unique', 'All')]
75-
[string[]]$Type = 'All'
88+
[string[]]$Type = 'All',
89+
[switch]$Absolute,
90+
[switch]$Relative,
91+
[switch]$NoRecurse,
92+
[string[]]$Match
7693
)
77-
94+
7895
begin {
7996
if (!$Build) {
8097
$Build = Get-NewBuildNumber
8198
}
8299
$scriptCollection = @()
83100
}
84101
process {
85-
foreach ($scriptItem in $ScriptPath) {
86-
Write-PSFMessage -Level Verbose -Message "Processing path item $scriptItem"
87-
$scriptCollection += Get-ChildScriptItem $scriptItem
88-
}
102+
Write-PSFMessage -Level Verbose -Message "Processing path items $ScriptPath"
103+
$scriptCollection += Get-DbopsFile $ScriptPath
89104
}
90105
end {
91106
Write-PSFMessage -Level Verbose -Message "Loading package information from $Path"
@@ -97,14 +112,14 @@ function Add-DBOBuild {
97112
$includeFile = $Type -contains 'All'
98113
if ($Type -contains 'New') {
99114
#Check if the script path was already added in one of the previous builds
100-
if (!$package.SourcePathExists($childScript.SourcePath)) {
115+
if (!$package.PackagePathExists($childScript.PackagePath)) {
101116
$includeFile = $true
102-
Write-PSFMessage -Level Verbose -Message "File $($childScript.SourcePath) was not found among the package source files, adding to the list."
117+
Write-PSFMessage -Level Verbose -Message "File $($childScript.PackagePath) was not found among the package source files, adding to the list."
103118
}
104119
}
105120
if ($Type -contains 'Modified') {
106121
#Check if the file was modified in the previous build
107-
if ($package.ScriptModified($childScript.FullName, $childScript.SourcePath)) {
122+
if ($package.ScriptModified($childScript)) {
108123
$includeFile = $true
109124
Write-PSFMessage -Level Verbose -Message "Hash of the file $($childScript.FullName) was modified since last deployment, adding to the list."
110125
}
@@ -125,13 +140,12 @@ function Add-DBOBuild {
125140
}
126141

127142
if ($scriptsToAdd) {
128-
129143
#Create new build object
130144
$currentBuild = $package.NewBuild($Build)
131145

132146
foreach ($buildScript in $scriptsToAdd) {
133-
$s = $currentBuild.NewScript($buildScript)
134-
Write-PSFMessage -Level Verbose -Message "Adding file '$($buildScript.FullName)' to $currentBuild as $($s.GetPackagePath())"
147+
$currentBuild.AddScript($buildScript)
148+
Write-PSFMessage -Level Verbose -Message "Adding file '$($buildScript.FullName)' to $currentBuild as $($buildScript.GetPackagePath())"
135149
}
136150

137151
if ($pscmdlet.ShouldProcess($package, "Writing new build $currentBuild into the original package")) {

functions/Install-DBOSqlScript.ps1

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,19 @@
9999
Additional connection string attributes that should be added to the existing connection string, provided as a hashtable.
100100
For example to enable SYSDBA permissions in Oracle, use the following: -ConnectionAttribute @{ 'DBA Privilege' = 'SYSDBA' }
101101
102+
.PARAMETER Absolute
103+
All the files in -Path will be installed using their absolute paths instead of relative.
104+
105+
.PARAMETER Relative
106+
Use current location to build relative paths instead of starting from the folder in -Path.
107+
108+
.PARAMETER NoRecurse
109+
Only process the first level of the target -Path.
110+
111+
.PARAMETER Match
112+
Runs a regex verification against provided file names using the provided Match string.
113+
Example: .*\.sql
114+
102115
.PARAMETER Confirm
103116
Prompts to confirm certain actions
104117
@@ -168,7 +181,11 @@
168181
[string]$ConnectionString,
169182
[Alias('ConnectionType', 'ServerType')]
170183
[DBOps.ConnectionType]$Type = (Get-DBODefaultSetting -Name rdbms.type -Value),
171-
[hashtable]$ConnectionAttribute
184+
[hashtable]$ConnectionAttribute,
185+
[switch]$Absolute,
186+
[switch]$Relative,
187+
[switch]$NoRecurse,
188+
[string[]]$Match
172189
)
173190

174191
begin {
@@ -203,7 +220,7 @@
203220

204221
#Prepare deployment function call parameters
205222
$params = @{
206-
ScriptPath = $scripts
223+
ScriptFile = Get-DbopsFile -Path $scripts
207224
Configuration = $config
208225
}
209226
foreach ($key in ($PSBoundParameters.Keys)) {

functions/Invoke-DBODeployment.ps1

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
.PARAMETER InputObject
1515
DBOpsPackage object to deploy. Supports pipelining.
1616
17-
.PARAMETER ScriptPath
17+
.PARAMETER ScriptFile
1818
A collection of script files to deploy to the server. Accepts Get-Item/Get-ChildItem objects and wildcards.
1919
Will recursively add all of the subfolders inside folders. See examples if you want only custom files to be added.
2020
During deployment, scripts will be following this deployment order:
21-
- Item order provided in the ScriptPath parameter
21+
- Item order provided in the ScriptFile parameter
2222
- Files inside each child folder (both folders and files in alphabetical order)
2323
- Files inside the root folder (in alphabetical order)
2424
@@ -73,7 +73,7 @@
7373
[string]$PackageFile = ".\dbops.package.json",
7474
[parameter(ParameterSetName = 'Script')]
7575
[Alias('SourcePath')]
76-
[string[]]$ScriptPath,
76+
[object[]]$ScriptFile,
7777
[parameter(ParameterSetName = 'PackageObject')]
7878
[Alias('Package')]
7979
[object]$InputObject,
@@ -140,16 +140,20 @@
140140
}
141141
}
142142
else {
143-
foreach ($scriptItem in (Get-ChildScriptItem $ScriptPath)) {
144-
Write-PSFMessage -Level Debug -Message "Adding deployment script $($scriptItem.SourcePath)"
143+
foreach ($scriptItem in $ScriptFile) {
144+
if ($scriptItem -and $scriptItem -isnot [DBOpsFile]) {
145+
Stop-PSFFunction -Message "Expected DBOpsFile object, got [$($scriptItem.GetType().FullName)]." -EnableException $true
146+
return
147+
}
148+
Write-PSFMessage -Level Debug -Message "Adding deployment script $($scriptItem.FullName)"
145149
if (!$RegisterOnly) {
146150
# Replace tokens in the scripts
147-
$scriptContent = Resolve-VariableToken (Get-Content $scriptItem.FullName -Raw) $runtimeVariables
151+
$scriptContent = Resolve-VariableToken $scriptItem.GetContent() $runtimeVariables
148152
}
149153
else {
150154
$scriptContent = ""
151155
}
152-
$scriptCollection += [DbUp.Engine.SqlScript]::new($scriptItem.SourcePath, $scriptContent)
156+
$scriptCollection += [DbUp.Engine.SqlScript]::new($scriptItem.FullName, $scriptContent)
153157
}
154158
}
155159

@@ -186,8 +190,8 @@
186190
}
187191
$status.ConnectionType = $Type
188192
if ($PsCmdlet.ParameterSetName -eq 'Script') {
189-
foreach ($p in $ScriptPath) {
190-
$status.SourcePath += Join-PSFPath -Normalize $p
193+
foreach ($p in $ScriptFile) {
194+
$status.SourcePath += Join-PSFPath -Normalize $p.FullName
191195
}
192196
}
193197
else {

functions/Invoke-DBOPackageCI.ps1

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function Invoke-DBOPackageCI {
22
<#
33
.SYNOPSIS
44
Prepares the scripts from the source folder to be deployed using DBOps packaging system
5-
5+
66
.DESCRIPTION
77
For a newly defined process, creates a new DBOps package from all the files in the specified folder
88
For existing process, updates the current version of the package by creating
@@ -14,25 +14,25 @@ function Invoke-DBOPackageCI {
1414
Each build will be assigned with a version using [System.Version] object. Each new build will have
1515
an increase in the build number, however, Major/Minor versions will stay the same unless the
1616
function is explicitly called with the new -Version
17-
17+
1818
.PARAMETER ScriptPath
1919
A collection of folders to scan. Accepts Get-Item/Get-ChildItem objects and wildcards.
2020
Will recursively add all of the subfolders inside folders. See examples if you want only custom files to be added.
2121
During deployment, scripts will be following this deployment order:
2222
- Item order provided in the ScriptPath parameter
2323
- Files inside each child folder (both folders and files in alphabetical order)
2424
- Files inside the root folder (in alphabetical order)
25-
25+
2626
Aliases: SourcePath
27-
27+
2828
.PARAMETER Path
2929
Path to the existing DBOpsPackage.
3030
Aliases: Name, FileName, Package
31-
31+
3232
.PARAMETER Version
3333
A string that is indended to represent the Major/Minor versions of the current package.
3434
Optional if the package already exists.
35-
35+
3636
Will be used to construct the new build version: specifying '2.4' will result in build '2.4.1' for new packages
3737
3838
For existing packages will compare the versions and continue to increase the build number by 1, but only if
@@ -47,11 +47,24 @@ function Invoke-DBOPackageCI {
4747
* Modified: adds files only if they have been modified since they had last been added to the package
4848
* Unique: adds unique files to the build based on their hash values. Compares hashes accross the whole package
4949
* All: add all files regardless of their previous involvement
50-
50+
5151
More than one value can be specified at the same time.
52-
52+
5353
Default value: New, and it's strongly recommended to keep it that way!
54-
54+
55+
.PARAMETER Absolute
56+
All the files in -Path will be added using their absolute paths instead of relative.
57+
58+
.PARAMETER Relative
59+
Use current location to build relative paths instead of starting from the folder in -Path.
60+
61+
.PARAMETER NoRecurse
62+
Only process the first level of the target -Path.
63+
64+
.PARAMETER Match
65+
Runs a regex verification against provided file names using the provided Match string.
66+
Example: .*\.sql
67+
5568
.PARAMETER Confirm
5669
Prompts to confirm certain actions
5770
@@ -79,9 +92,13 @@ function Invoke-DBOPackageCI {
7992
[object[]]$ScriptPath,
8093
[Version]$Version,
8194
[ValidateSet('New', 'Modified', 'Unique', 'All')]
82-
[string[]]$Type = 'New'
95+
[string[]]$Type = 'New',
96+
[switch]$Absolute,
97+
[switch]$Relative,
98+
[switch]$NoRecurse,
99+
[string[]]$Match
83100
)
84-
101+
85102
begin {
86103

87104
}
@@ -114,15 +131,22 @@ function Invoke-DBOPackageCI {
114131
$pkgVersion = [Version]::new($pkgVersion.Major, $pkgVersion.Minor, $pkgVersion.Build + 1)
115132
Write-PSFMessage -Message "Building version $pkgVersion" -Level Verbose
116133

117-
134+
$ciSplat = @{
135+
Absolute = $Absolute
136+
Relative = $Relative
137+
NoRecurse = $NoRecurse
138+
Match = $Match
139+
ScriptPath = $ScriptPath
140+
Build = $pkgVersion.ToString(3)
141+
}
118142
if ($pkg) {
119143
if ($PSCmdlet.ShouldProcess($pkg, "Adding new build to existing package")) {
120-
Add-DBOBuild -Package $pkg -ScriptPath $ScriptPath -Type $Type -Build $pkgVersion.ToString(3)
144+
Add-DBOBuild @ciSplat -Package $pkg -Type $Type
121145
}
122146
}
123147
else {
124148
if ($PSCmdlet.ShouldProcess($Path, "Creating new package")) {
125-
New-DBOPackage -Name $Path -ScriptPath $ScriptPath -Build $pkgVersion.ToString(3)
149+
New-DBOPackage @ciSplat -Name $Path
126150
}
127151
}
128152
}

functions/Invoke-DBOQuery.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ function Invoke-DBOQuery {
432432
}
433433
finally {
434434
# close the connection even when interrupted by Ctrl+C
435+
$dataConnection.Close()
435436
$dataConnection.Dispose()
436437
}
437438
}

0 commit comments

Comments
 (0)