Skip to content

Commit a322c77

Browse files
author
Kirill Kravtsov
committed
Fixing paths in the script deployment scenarios
1 parent 9ca7dd3 commit a322c77

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

functions/Invoke-DBODeployment.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@
145145
Stop-PSFFunction -Message "Expected DBOpsFile object, got [$($scriptItem.GetType().FullName)]." -EnableException $true
146146
return
147147
}
148-
Write-PSFMessage -Level Debug -Message "Adding deployment script $($scriptItem.FullName)"
148+
Write-PSFMessage -Level Debug -Message "Adding deployment script $($scriptItem.FullName) as $($scriptItem.PackagePath)"
149149
if (!$RegisterOnly) {
150150
# Replace tokens in the scripts
151151
$scriptContent = Resolve-VariableToken $scriptItem.GetContent() $runtimeVariables
152152
}
153153
else {
154154
$scriptContent = ""
155155
}
156-
$scriptCollection += [DbUp.Engine.SqlScript]::new($scriptItem.FullName, $scriptContent)
156+
$scriptCollection += [DbUp.Engine.SqlScript]::new($scriptItem.PackagePath, $scriptContent)
157157
}
158158
}
159159

tests/postgresql/Install-DBOSqlScript.Tests.ps1

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,35 @@ Describe "Install-DBOSqlScript PostgreSQL integration tests" -Tag $commandName,
177177
'd' | Should BeIn $testResults.name
178178
}
179179
}
180+
Context "testing relative paths" {
181+
BeforeAll {
182+
$null = Invoke-DBOQuery @connParams -Database postgres -Query $dropDatabaseScript
183+
[Npgsql.NpgsqlConnection]::ClearAllPools()
184+
$null = Invoke-DBOQuery @connParams -Database postgres -Query $createDatabaseScript
185+
}
186+
It "should deploy version 1.0" {
187+
$testResults = Install-DBOSqlScript -Relative -Type PostgreSQL -ScriptPath $v1scripts -SqlInstance $script:postgresqlInstance -Credential $script:postgresqlCredential -Database $newDbName -SchemaVersionTable $logTable -Silent
188+
$testResults.Successful | Should Be $true
189+
$testResults.Scripts.Name | Should Be ((Resolve-Path $v1scripts -Relative) -replace '^.[\\|\/]', '')
190+
$testResults.SqlInstance | Should Be $script:postgresqlInstance
191+
$testResults.Database | Should Be $newDbName
192+
$testResults.SourcePath | Should Be $v1scripts
193+
$testResults.ConnectionType | Should Be 'PostgreSQL'
194+
$testResults.Configuration.SchemaVersionTable | Should Be $logTable
195+
$testResults.Error | Should BeNullOrEmpty
196+
$testResults.Duration.TotalMilliseconds | Should -BeGreaterOrEqual 0
197+
$testResults.StartTime | Should Not BeNullOrEmpty
198+
$testResults.EndTime | Should Not BeNullOrEmpty
199+
$testResults.EndTime | Should -BeGreaterOrEqual $testResults.StartTime
200+
'Upgrade successful' | Should BeIn $testResults.DeploymentLog
201+
202+
#Verifying objects
203+
$testResults = Invoke-DBOQuery -Type PostgreSQL -SqlInstance $script:postgresqlInstance -Silent -Credential $script:postgresqlCredential -Database $newDbName -InputFile $verificationScript
204+
$logTable | Should BeIn $testResults.name
205+
'a' | Should BeIn $testResults.name
206+
'b' | Should BeIn $testResults.name
207+
}
208+
}
180209
Context "testing deployment order" {
181210
BeforeAll {
182211
$null = Invoke-DBOQuery @connParams -Database postgres -Query $dropDatabaseScript
@@ -329,9 +358,9 @@ Describe "Install-DBOSqlScript PostgreSQL integration tests" -Tag $commandName,
329358
It "should deploy version 1.0" {
330359
$before = Invoke-DBOQuery -Type PostgreSQL -SqlInstance $script:postgresqlInstance -Silent -Credential $script:postgresqlCredential -Database $newDbName -InputFile $verificationScript
331360
$rowsBefore = ($before | Measure-Object).Count
332-
$testResults = Install-DBOSqlScript -Absolute -Type PostgreSQL -ScriptPath $v1scripts -SqlInstance $script:postgresqlInstance -Credential $script:postgresqlCredential -Database $newDbName -Silent
361+
$testResults = Install-DBOSqlScript -Type PostgreSQL -ScriptPath $v1scripts -SqlInstance $script:postgresqlInstance -Credential $script:postgresqlCredential -Database $newDbName -Silent
333362
$testResults.Successful | Should Be $true
334-
$testResults.Scripts.Name | Should Be (Resolve-Path $v1scripts).Path
363+
$testResults.Scripts.Name | Should Be (Get-Item $v1scripts).Name
335364
$testResults.SqlInstance | Should Be $script:postgresqlInstance
336365
$testResults.Database | Should Be $newDbName
337366
$testResults.SourcePath | Should Be $v1scripts
@@ -356,9 +385,9 @@ Describe "Install-DBOSqlScript PostgreSQL integration tests" -Tag $commandName,
356385
It "should deploy version 2.0" {
357386
$before = Invoke-DBOQuery -Type PostgreSQL -SqlInstance $script:postgresqlInstance -Silent -Credential $script:postgresqlCredential -Database $newDbName -InputFile $verificationScript
358387
$rowsBefore = ($before | Measure-Object).Count
359-
$testResults = Install-DBOSqlScript -Absolute -Type PostgreSQL -ScriptPath $v2scripts -SqlInstance $script:postgresqlInstance -Credential $script:postgresqlCredential -Database $newDbName -Silent
388+
$testResults = Install-DBOSqlScript -Type PostgreSQL -ScriptPath $v2scripts -SqlInstance $script:postgresqlInstance -Credential $script:postgresqlCredential -Database $newDbName -Silent
360389
$testResults.Successful | Should Be $true
361-
$testResults.Scripts.Name | Should Be (Resolve-Path $v2scripts).Path
390+
$testResults.Scripts.Name | Should Be (Get-Item $v2scripts).Name
362391
$testResults.SqlInstance | Should Be $script:postgresqlInstance
363392
$testResults.Database | Should Be $newDbName
364393
$testResults.SourcePath | Should Be $v2scripts

0 commit comments

Comments
 (0)