Skip to content

Commit

Permalink
Merge pull request #109 from sqlcollaborative/development
Browse files Browse the repository at this point in the history
0.6.2
  • Loading branch information
nvarscar authored Feb 15, 2020
2 parents 1c90cdb + 076464f commit fb2da95
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 11 deletions.
19 changes: 11 additions & 8 deletions bin/deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,25 @@ foreach ($module in @('PSFramework', 'dbops')) {
Import-Module "$PSScriptRoot\Modules\$module"
}
}

$config = Get-DBOConfig -Path "$PSScriptRoot\dbops.config.json" -Configuration $Configuration
#Open package from the current folder
$package = Get-DBOPackage -Path $PSScriptRoot -Unpacked
#Merge configuration if provided
if ($Configuration) {
$package.Configuration.Merge($Configuration)
}

#Merge custom parameters into a configuration
$newConfig = @{}
$newConfig = @{ }
foreach ($key in ($PSBoundParameters.Keys)) {
if ($key -in [DBOps.ConfigProperty].GetEnumNames()) {
$newConfig.$key = $PSBoundParameters[$key]
}
}
$config.Merge($newConfig)
$package.Configuration.Merge($newConfig)

#Prepare deployment function call parameters
$params = @{
PackageFile = "$PSScriptRoot\dbops.package.json"
Configuration = $config
InputObject = $package
}
foreach ($key in ($PSBoundParameters.Keys)) {
#If any custom properties were specified
Expand All @@ -62,9 +65,9 @@ foreach ($key in ($PSBoundParameters.Keys)) {
}

if ($PSCmdlet.ShouldProcess($params.PackageFile, "Initiating the deployment of the package")) {
Invoke-DBODeployment @params
Install-DBOPackage @params
}
else {
Invoke-DBODeployment @params -WhatIf
Install-DBOPackage @params -WhatIf
}

2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Release notes for v0.6.2:
- ### Ensuring deploy.ps1 only uses public functions (#108) by @nvarscar
# Release notes for v0.6.1:
- ### Files in subfolders are not being added when -Match is used (#104) by @nvarscar
------
Expand Down
4 changes: 2 additions & 2 deletions tests/DBOpsPackage.class.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Describe "DBOpsPackage class tests" -Tag $commandName, UnitTests, DBOpsPackage {
$pkg = [DBOpsPackage]::new()
$pkg.ScriptDirectory | Should Be 'content'
$pkg.DeployFile.ToString() | Should Be 'Deploy.ps1'
$pkg.DeployFile.GetContent() | Should BeLike '*Invoke-DBODeployment @params*'
$pkg.DeployFile.GetContent() | Should BeLike '*Install-DBOPackage @params*'
$pkg.Configuration.SchemaVersionTable | Should Be 'SchemaVersions'
$pkg.FileName | Should BeNullOrEmpty
$pkg.Version | Should BeNullOrEmpty
Expand Down Expand Up @@ -73,7 +73,7 @@ Describe "DBOpsPackage class tests" -Tag $commandName, UnitTests, DBOpsPackage {
$pkg = [DBOpsPackage]::new($packageName)
$pkg.ScriptDirectory | Should Be 'content'
$pkg.DeployFile.ToString() | Should Be 'Deploy.ps1'
$pkg.DeployFile.GetContent() | Should BeLike '*Invoke-DBODeployment @params*'
$pkg.DeployFile.GetContent() | Should BeLike '*Install-DBOPackage @params*'
$pkg.ConfigurationFile.ToString() | Should Be 'dbops.config.json'
($pkg.ConfigurationFile.GetContent() | ConvertFrom-Json).SchemaVersionTable | Should Be 'SchemaVersions'
$pkg.Configuration.SchemaVersionTable | Should Be 'SchemaVersions'
Expand Down
2 changes: 1 addition & 1 deletion tests/DBOpsPackageFile.class.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Describe "DBOpsPackageFile class tests" -Tag $commandName, UnitTests, DBOpsPacka
$p = [DBOpsPackageFile]::new((Join-PSFPath -Normalize "$here\etc\LoadFromFile\dbops.package.json"))
$p.ScriptDirectory | Should Be 'content'
$p.DeployFile.ToString() | Should Be 'Deploy.ps1'
$p.DeployFile.GetContent() | Should BeLike '*Invoke-DBODeployment @params*'
$p.DeployFile.GetContent() | Should BeLike '*Install-DBOPackage @params*'
$p.ConfigurationFile.ToString() | Should Be 'dbops.config.json'
($p.ConfigurationFile.GetContent() | ConvertFrom-Json).SchemaVersionTable | Should Be 'SchemaVersions'
$p.Configuration.SchemaVersionTable | Should Be 'SchemaVersions'
Expand Down
60 changes: 60 additions & 0 deletions tests/deploy.ps1.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,66 @@ Describe "deploy.ps1 integration tests" -Tag $commandName, IntegrationTests {
'c' | Should Not BeIn $testResults.name
'd' | Should Not BeIn $testResults.name
}
It "should deploy with no components loaded" {
$scriptBlock = {
param (
$Path,
$DotSource,
$Database
)
. $DotSource
$testResults = & $Path\deploy.ps1 -SqlInstance $script:mssqlInstance -Credential $script:mssqlCredential -Database $Database -Silent
$testResults.Successful | Should -Be $true
$testResults.Scripts.Name | Should -Not -BeNullOrEmpty
$testResults.SqlInstance | Should -Be $script:mssqlInstance
$testResults.Database | Should Be $Database
$testResults.SourcePath | Should Be $Path
$testResults.ConnectionType | Should Be 'SQLServer'
$testResults.Configuration.SchemaVersionTable | Should Be 'SchemaVersions'
$testResults.Error | Should BeNullOrEmpty
$testResults.Duration.TotalMilliseconds | Should -BeGreaterOrEqual 0
$testResults.StartTime | Should -Not -BeNullOrEmpty
$testResults.EndTime | Should -Not -BeNullOrEmpty
$testResults.EndTime | Should -BeGreaterOrEqual $testResults.StartTime
Get-ChildItem function:\ | Where-Object Name -eq Invoke-DBODeployment | Should -BeNullOrEmpty
}
$job = Start-Job -ScriptBlock $scriptBlock -ArgumentList $workFolder, "$here\constants.ps1", $newDbName
$job | Wait-Job | Receive-Job -ErrorAction Stop
# # Get modules
# $modules = Get-Module Pester | Select-Object -ExpandProperty Path
# $sessionstate = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault()
# foreach ($modulePath in $modules) {
# $sessionstate.ImportPSModule($modulePath)
# }
# # Create runspace pool
# $runspacepool = [runspacefactory]::CreateRunspacePool(1, 5, $sessionstate, $Host)
# $runspacepool.Open()
# $powershell = [powershell]::Create()
# $params = @{
# Path = $workFolder
# Instance = $script:mssqlInstance
# Credential = $script:mssqlCredential
# Database = $newDbName
# }
# [void]$powershell.AddScript($scriptBlock).AddParameters($params)
# $powershell.RunspacePool = $runspacepool
# try {
# $handle = $powershell.BeginInvoke()
# $cycles = 0
# do { Start-Sleep 1; $cycles++ } while (-not $handle.IsCompleted -and $cycles -lt 5)
# if ($powershell.Streams.Error.Count -gt 0) {
# throw $powershell.Streams.Error[0]
# }
# $powershell.EndInvoke($handle)
# }
# catch {
# throw $_
# }
# finally {
# $powershell.Dispose()
# $runspacepool.Close()
# }
}
}
Context "$commandName whatif tests" {
BeforeAll {
Expand Down
5 changes: 5 additions & 0 deletions tests/postgresql/Invoke-DBOQuery.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ Describe "Invoke-DBOQuery PostgreSQL tests" -Tag $commandName, IntegrationTests
$result.varchar | Should -Be ([DBNull]::Value)
$result.timestamp | Should -Be ([DBNull]::Value)
}
It "should process 0 rows" {
$query = "SELECT 1 WHERE 1 = 0"
$result = Invoke-DBOQuery -Query $query @connParams
$result | Should -BeNullOrEmpty
}
It "should run the query with semicolon" {
$query = "SELECT 1 AS A, 2 AS B;
SELECT 3 AS A, 4 AS B"
Expand Down

0 comments on commit fb2da95

Please sign in to comment.