Skip to content

Commit d1e1edd

Browse files
authored
Merge pull request #144 from dataplat/development
v0.8.0
2 parents 7ded3d2 + 410f309 commit d1e1edd

12 files changed

+64
-13
lines changed

build/bump_version.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Param (
22
$Path = '.\dbops.psd1'
33
)
4-
git config --global user.email $env:git_user_email
5-
git config --global user.name $env:git_username
4+
git config --global user.email $env:GIT_USER_EMAIL
5+
git config --global user.name $env:GIT_USERNAME
66
$moduleFile = Invoke-Command -ScriptBlock ([scriptblock]::Create((Get-Content $Path -Raw)))
77
$version = [Version]$moduleFile.ModuleVersion
88
$regEx = "^([\s]*ModuleVersion[\s]*\=[\s]*)\'(" + [regex]::Escape($version) + ")\'[\s]*`$"

dbops.psd1

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
RootModule = 'dbops.psm1'
55

66
# Version number of this module.
7-
ModuleVersion = '0.7.0'
7+
ModuleVersion = '0.7.1'
88

99
# ID used to uniquely identify this module
1010
GUID = '16dff216-533a-4fa3-9b2e-4408dbe15e63'

dbops.psm1

+24-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,25 @@ Register-PSFConfigValidation -Name "connectionType" -ScriptBlock {
116116
return $Result
117117
}
118118

119+
Register-PSFConfigValidation -Name "errorAction" -ScriptBlock {
120+
Param (
121+
$Value
122+
)
123+
$Result = New-Object PSObject -Property @{
124+
Success = $True
125+
Value = $null
126+
Message = ""
127+
}
128+
try {
129+
$Result.Value = [String][System.Management.Automation.ActionPreference]$Value
130+
}
131+
catch {
132+
$Result.Message = $_.Exception.Message
133+
$Result.Success = $False
134+
}
135+
return $Result
136+
}
137+
119138
Register-PSFConfigValidation -Name "tokenRegex" -ScriptBlock {
120139
Param (
121140
$Value
@@ -175,6 +194,10 @@ Set-PSFConfig -FullName dbops.package.slim -Value $false -Validation bool -Initi
175194
Set-PSFConfig -FullName dbops.config.variabletoken -Value "\#\{(token)\}" -Validation tokenRegex -Initialize -Description "Variable replacement token. Regex string that will be replaced with values from -Variables parameters. Default: \#\{(token)\}"
176195
$dotNet = try { dotnet --version } catch { $null }
177196
Set-PSFConfig -FullName dbops.runtime.dotnetversion -Value ($dotNet -as [version]) -Description "Current dotnet runtime." -Hidden
197+
Set-PSFConfig -FullName dbops.ErrorActionPreference -Value Stop -Initialize -Description "Module ErrorAction default value" -Validation errorAction
198+
199+
# Module-wide ErrorAction preference
200+
$ErrorActionPreference = Get-PSFConfigValue -FullName dbops.ErrorActionPreference
178201

179202
# extensions for SMO
180203
$typeData = Get-TypeData -TypeName 'Microsoft.SqlServer.Management.Smo.Database'
@@ -213,4 +236,4 @@ $aliases = @(
213236
)
214237
$aliases | ForEach-Object {
215238
if (-not (Test-Path Alias:$($_.AliasName))) { Set-Alias -Scope Global -Name $($_.AliasName) -Value $($_.Definition) }
216-
}
239+
}

docs/changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Release notes for v0.8.0:
2+
- ### Hotfix: Nuget downloads now use lowercase filename in the URL (#139) by @nvarscar
3+
- ### Feature: Allow ErrorAction to properly handle errors (#140) by @nvarscar
4+
- ### Setting default encoding to UTF8 (#142) by @nvarscar
15
# Release notes for v0.7.1:
26
- ### Adding support for underscore char in tokens (#130) by @nvarscar
37
# Release notes for v0.7.0:

functions/Invoke-DBOQuery.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ function Invoke-DBOQuery {
427427
}
428428
catch {
429429
# don't really need anything else here
430-
throw $_
430+
Write-Error $_
431431
}
432432
finally {
433433
# close the connection even when interrupted by Ctrl+C

internal/classes/DBOpsDeploymentStatus.class.ps1

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class DBOpsDeploymentStatus {
1010
[System.Nullable[datetime]] $StartTime
1111
[System.Nullable[datetime]] $EndTime
1212
[string[]] $DeploymentLog
13+
[string] $ErrorScript
1314

1415
DBOpsDeploymentStatus() {
1516
Add-Member -InputObject $this -MemberType ScriptProperty -Name Duration -Value {

internal/classes/DBOpsHelper.class.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ class DBOpsHelper {
137137
$encoding = [System.Text.Encoding]::UTF7
138138
}
139139
else {
140-
$encoding = [System.Text.Encoding]::ASCII
140+
$encoding = [System.Text.Encoding]::UTF8
141141
}
142142
return $encoding.GetString($Array, $skipBytes, $Array.Length - $skipBytes)
143143
}
144144
# scrubs nulls from the datatable
145-
static [PSObject] DataRowToPSObject([DataRow] $row){
145+
static [PSObject] DataRowToPSObject([DataRow] $row) {
146146
$psObject = [PSObject]::new()
147147
if ($null -ne $row -and $row.RowState -and $row.RowState -ne [DataRowState]::Detached) {
148148
foreach ($column in $row.Table.Columns) {

internal/functions/Install-NugetPackage.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function Install-NugetPackage {
6666

6767
# download and extract the files
6868
Write-PSFMessage -Level Verbose -Message "Version $selectedVersion of $packageName was selected"
69-
$fileName = "$packageName.$selectedVersion.nupkg"
69+
$fileName = "$packageName.$selectedVersion.nupkg".ToLower()
7070
# Path reference: https://github.com/OneGet/oneget/blob/master/src/Microsoft.PackageManagement/Utility/Platform/OSInformation.cs
7171
$scopePath = switch ($Scope) {
7272
'AllUsers' {

internal/functions/Invoke-Deployment.ps1

+5-2
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@
134134
if (!$Status.Successful) {
135135
# Throw output error if unsuccessful
136136
if ($Status.Error) {
137+
if ($upgradeResult.errorScript) {
138+
$Status.ErrorScript = $upgradeResult.errorScript.Name
139+
}
137140
throw $Status.Error
138141
}
139142
else {
@@ -349,12 +352,12 @@
349352
}
350353
}
351354
catch {
352-
throw $_
355+
Write-Error $_
353356
}
354357
finally {
355358
$status.EndTime = [datetime]::Now
356-
$status
357359
}
360+
return $status
358361
}
359362
}
360363
end { }

internal/xml/dbops.format.ps1xml

+3
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@
108108
<ListItem>
109109
<PropertyName>Duration</PropertyName>
110110
</ListItem>
111+
<ListItem>
112+
<PropertyName>ErrorScript</PropertyName>
113+
</ListItem>
111114
</ListItems>
112115
</ListEntry>
113116
</ListEntries>

tests/Install-DBOScript.Tests.ps1

+19-3
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,8 @@ Describe "Install-DBOScript integration tests" -Tag $commandName, IntegrationTes
457457
}
458458
}
459459
Context "deployments with errors should throw terminating errors" {
460-
BeforeAll {
460+
BeforeEach {
461461
$null = Invoke-DBOQuery @connParams -InputFile $cleanupScript
462-
$null = Install-DBOScript -Absolute -ScriptPath $v1scripts @connParams -SchemaVersionTable $null
463462
}
464463
It "Should return terminating error when object exists" {
465464
#Running package
@@ -474,6 +473,23 @@ Describe "Install-DBOScript integration tests" -Tag $commandName, IntegrationTes
474473
$errorObject | Should Not BeNullOrEmpty
475474
$errorObject.Exception.Message | Should Be "There is already an object named 'a' in the database."
476475
}
476+
It "Should return failure results with SilentlyContinue" {
477+
$testResults = Install-DBOScript -Absolute -Path $tranFailScripts -SchemaVersionTable $logTable -DeploymentMethod NoTransaction @connParams -ErrorAction SilentlyContinue
478+
$testResults | Should -Not -Be $null
479+
$testResults.Successful | Should -Be $false
480+
$testResults.SqlInstance | Should Be $script:mssqlInstance
481+
$testResults.Database | Should Be $newDbName
482+
$testResults.SourcePath | Should Be (Get-ChildItem $tranFailScripts).FullName
483+
$testResults.ConnectionType | Should Be 'SQLServer'
484+
$testResults.Configuration.SchemaVersionTable | Should -Be $logTable
485+
$testResults.Error.Message | Should Be "There is already an object named 'a' in the database."
486+
$testResults.ErrorScript | Should -Be (Get-ChildItem $tranFailScripts)[1].FullName
487+
$testResults.Scripts.Name | Should Be (Get-ChildItem $tranFailScripts)[0].FullName
488+
$testResults.Duration.TotalMilliseconds | Should -BeGreaterOrEqual 0
489+
$testResults.StartTime | Should -Not -BeNullOrEmpty
490+
$testResults.EndTime | Should -Not -BeNullOrEmpty
491+
$testResults.EndTime | Should -BeGreaterOrEqual $testResults.StartTime
492+
}
477493
It "should not deploy anything after throwing an error" {
478494
#Running package
479495
try {
@@ -490,7 +506,7 @@ Describe "Install-DBOScript integration tests" -Tag $commandName, IntegrationTes
490506
#Verifying objects
491507
$testResults = Invoke-DBOQuery @connParams -InputFile $verificationScript
492508
'a' | Should BeIn $testResults.name
493-
'b' | Should BeIn $testResults.name
509+
'b' | Should Not BeIn $testResults.name
494510
'c' | Should Not BeIn $testResults.name
495511
'd' | Should Not BeIn $testResults.name
496512
}

tests/Invoke-Deployment.Tests.ps1

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ else {
1515
Write-Host "Running $commandName tests" -ForegroundColor Cyan
1616
}
1717

18+
$ErrorActionPreference = 'Stop' # Needed for non-public commands
1819
. "$here\constants.ps1"
1920

2021
$workFolder = Join-PSFPath -Normalize "$here\etc" "$commandName.Tests.dbops"

0 commit comments

Comments
 (0)