Skip to content

Commit fb2da95

Browse files
authored
Merge pull request #109 from sqlcollaborative/development
0.6.2
2 parents 1c90cdb + 076464f commit fb2da95

File tree

6 files changed

+81
-11
lines changed

6 files changed

+81
-11
lines changed

bin/deploy.ps1

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,25 @@ foreach ($module in @('PSFramework', 'dbops')) {
3737
Import-Module "$PSScriptRoot\Modules\$module"
3838
}
3939
}
40-
41-
$config = Get-DBOConfig -Path "$PSScriptRoot\dbops.config.json" -Configuration $Configuration
40+
#Open package from the current folder
41+
$package = Get-DBOPackage -Path $PSScriptRoot -Unpacked
42+
#Merge configuration if provided
43+
if ($Configuration) {
44+
$package.Configuration.Merge($Configuration)
45+
}
4246

4347
#Merge custom parameters into a configuration
44-
$newConfig = @{}
48+
$newConfig = @{ }
4549
foreach ($key in ($PSBoundParameters.Keys)) {
4650
if ($key -in [DBOps.ConfigProperty].GetEnumNames()) {
4751
$newConfig.$key = $PSBoundParameters[$key]
4852
}
4953
}
50-
$config.Merge($newConfig)
54+
$package.Configuration.Merge($newConfig)
5155

5256
#Prepare deployment function call parameters
5357
$params = @{
54-
PackageFile = "$PSScriptRoot\dbops.package.json"
55-
Configuration = $config
58+
InputObject = $package
5659
}
5760
foreach ($key in ($PSBoundParameters.Keys)) {
5861
#If any custom properties were specified
@@ -62,9 +65,9 @@ foreach ($key in ($PSBoundParameters.Keys)) {
6265
}
6366

6467
if ($PSCmdlet.ShouldProcess($params.PackageFile, "Initiating the deployment of the package")) {
65-
Invoke-DBODeployment @params
68+
Install-DBOPackage @params
6669
}
6770
else {
68-
Invoke-DBODeployment @params -WhatIf
71+
Install-DBOPackage @params -WhatIf
6972
}
7073

docs/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Release notes for v0.6.2:
2+
- ### Ensuring deploy.ps1 only uses public functions (#108) by @nvarscar
13
# Release notes for v0.6.1:
24
- ### Files in subfolders are not being added when -Match is used (#104) by @nvarscar
35
------

tests/DBOpsPackage.class.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Describe "DBOpsPackage class tests" -Tag $commandName, UnitTests, DBOpsPackage {
4141
$pkg = [DBOpsPackage]::new()
4242
$pkg.ScriptDirectory | Should Be 'content'
4343
$pkg.DeployFile.ToString() | Should Be 'Deploy.ps1'
44-
$pkg.DeployFile.GetContent() | Should BeLike '*Invoke-DBODeployment @params*'
44+
$pkg.DeployFile.GetContent() | Should BeLike '*Install-DBOPackage @params*'
4545
$pkg.Configuration.SchemaVersionTable | Should Be 'SchemaVersions'
4646
$pkg.FileName | Should BeNullOrEmpty
4747
$pkg.Version | Should BeNullOrEmpty
@@ -73,7 +73,7 @@ Describe "DBOpsPackage class tests" -Tag $commandName, UnitTests, DBOpsPackage {
7373
$pkg = [DBOpsPackage]::new($packageName)
7474
$pkg.ScriptDirectory | Should Be 'content'
7575
$pkg.DeployFile.ToString() | Should Be 'Deploy.ps1'
76-
$pkg.DeployFile.GetContent() | Should BeLike '*Invoke-DBODeployment @params*'
76+
$pkg.DeployFile.GetContent() | Should BeLike '*Install-DBOPackage @params*'
7777
$pkg.ConfigurationFile.ToString() | Should Be 'dbops.config.json'
7878
($pkg.ConfigurationFile.GetContent() | ConvertFrom-Json).SchemaVersionTable | Should Be 'SchemaVersions'
7979
$pkg.Configuration.SchemaVersionTable | Should Be 'SchemaVersions'

tests/DBOpsPackageFile.class.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Describe "DBOpsPackageFile class tests" -Tag $commandName, UnitTests, DBOpsPacka
5454
$p = [DBOpsPackageFile]::new((Join-PSFPath -Normalize "$here\etc\LoadFromFile\dbops.package.json"))
5555
$p.ScriptDirectory | Should Be 'content'
5656
$p.DeployFile.ToString() | Should Be 'Deploy.ps1'
57-
$p.DeployFile.GetContent() | Should BeLike '*Invoke-DBODeployment @params*'
57+
$p.DeployFile.GetContent() | Should BeLike '*Install-DBOPackage @params*'
5858
$p.ConfigurationFile.ToString() | Should Be 'dbops.config.json'
5959
($p.ConfigurationFile.GetContent() | ConvertFrom-Json).SchemaVersionTable | Should Be 'SchemaVersions'
6060
$p.Configuration.SchemaVersionTable | Should Be 'SchemaVersions'

tests/deploy.ps1.Tests.ps1

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,66 @@ Describe "deploy.ps1 integration tests" -Tag $commandName, IntegrationTests {
103103
'c' | Should Not BeIn $testResults.name
104104
'd' | Should Not BeIn $testResults.name
105105
}
106+
It "should deploy with no components loaded" {
107+
$scriptBlock = {
108+
param (
109+
$Path,
110+
$DotSource,
111+
$Database
112+
)
113+
. $DotSource
114+
$testResults = & $Path\deploy.ps1 -SqlInstance $script:mssqlInstance -Credential $script:mssqlCredential -Database $Database -Silent
115+
$testResults.Successful | Should -Be $true
116+
$testResults.Scripts.Name | Should -Not -BeNullOrEmpty
117+
$testResults.SqlInstance | Should -Be $script:mssqlInstance
118+
$testResults.Database | Should Be $Database
119+
$testResults.SourcePath | Should Be $Path
120+
$testResults.ConnectionType | Should Be 'SQLServer'
121+
$testResults.Configuration.SchemaVersionTable | Should Be 'SchemaVersions'
122+
$testResults.Error | Should BeNullOrEmpty
123+
$testResults.Duration.TotalMilliseconds | Should -BeGreaterOrEqual 0
124+
$testResults.StartTime | Should -Not -BeNullOrEmpty
125+
$testResults.EndTime | Should -Not -BeNullOrEmpty
126+
$testResults.EndTime | Should -BeGreaterOrEqual $testResults.StartTime
127+
Get-ChildItem function:\ | Where-Object Name -eq Invoke-DBODeployment | Should -BeNullOrEmpty
128+
}
129+
$job = Start-Job -ScriptBlock $scriptBlock -ArgumentList $workFolder, "$here\constants.ps1", $newDbName
130+
$job | Wait-Job | Receive-Job -ErrorAction Stop
131+
# # Get modules
132+
# $modules = Get-Module Pester | Select-Object -ExpandProperty Path
133+
# $sessionstate = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault()
134+
# foreach ($modulePath in $modules) {
135+
# $sessionstate.ImportPSModule($modulePath)
136+
# }
137+
# # Create runspace pool
138+
# $runspacepool = [runspacefactory]::CreateRunspacePool(1, 5, $sessionstate, $Host)
139+
# $runspacepool.Open()
140+
# $powershell = [powershell]::Create()
141+
# $params = @{
142+
# Path = $workFolder
143+
# Instance = $script:mssqlInstance
144+
# Credential = $script:mssqlCredential
145+
# Database = $newDbName
146+
# }
147+
# [void]$powershell.AddScript($scriptBlock).AddParameters($params)
148+
# $powershell.RunspacePool = $runspacepool
149+
# try {
150+
# $handle = $powershell.BeginInvoke()
151+
# $cycles = 0
152+
# do { Start-Sleep 1; $cycles++ } while (-not $handle.IsCompleted -and $cycles -lt 5)
153+
# if ($powershell.Streams.Error.Count -gt 0) {
154+
# throw $powershell.Streams.Error[0]
155+
# }
156+
# $powershell.EndInvoke($handle)
157+
# }
158+
# catch {
159+
# throw $_
160+
# }
161+
# finally {
162+
# $powershell.Dispose()
163+
# $runspacepool.Close()
164+
# }
165+
}
106166
}
107167
Context "$commandName whatif tests" {
108168
BeforeAll {

tests/postgresql/Invoke-DBOQuery.Tests.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ Describe "Invoke-DBOQuery PostgreSQL tests" -Tag $commandName, IntegrationTests
6666
$result.varchar | Should -Be ([DBNull]::Value)
6767
$result.timestamp | Should -Be ([DBNull]::Value)
6868
}
69+
It "should process 0 rows" {
70+
$query = "SELECT 1 WHERE 1 = 0"
71+
$result = Invoke-DBOQuery -Query $query @connParams
72+
$result | Should -BeNullOrEmpty
73+
}
6974
It "should run the query with semicolon" {
7075
$query = "SELECT 1 AS A, 2 AS B;
7176
SELECT 3 AS A, 4 AS B"

0 commit comments

Comments
 (0)