Skip to content

Commit e7af481

Browse files
committed
Merge 'origin/development' into feature/pester-5
2 parents 94e725f + 4ad4488 commit e7af481

11 files changed

Lines changed: 64 additions & 11 deletions

build/bump_version.ps1

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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.1'
7+
ModuleVersion = '0.8.1'
88

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

dbops.psm1

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,25 @@ Register-PSFConfigValidation -Name "connectionType" -ScriptBlock {
123123
return $Result
124124
}
125125

126+
Register-PSFConfigValidation -Name "errorAction" -ScriptBlock {
127+
Param (
128+
$Value
129+
)
130+
$Result = New-Object PSObject -Property @{
131+
Success = $True
132+
Value = $null
133+
Message = ""
134+
}
135+
try {
136+
$Result.Value = [String][System.Management.Automation.ActionPreference]$Value
137+
}
138+
catch {
139+
$Result.Message = $_.Exception.Message
140+
$Result.Success = $False
141+
}
142+
return $Result
143+
}
144+
126145
Register-PSFConfigValidation -Name "tokenRegex" -ScriptBlock {
127146
Param (
128147
$Value
@@ -180,8 +199,12 @@ Set-PSFConfig -FullName dbops.security.usecustomencryptionkey -Value ($PSVersion
180199
Set-PSFConfig -FullName dbops.rdbms.type -Value 'SqlServer' -Validation connectionType -Initialize -Description "Assumes a certain RDBMS as a default one for each command. SQLServer by default"
181200
Set-PSFConfig -FullName dbops.package.slim -Value $false -Validation bool -Initialize -Description "Decides whether to make the packages 'slim' and omit module files when creating the package. Default: `$false"
182201
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)\}"
183-
$dotNet = try { dotnet --version } catch { $null }
202+
$dotNet = try { & { dotnet --version } } catch { $null }
184203
Set-PSFConfig -FullName dbops.runtime.dotnetversion -Value ($dotNet -as [version]) -Description "Current dotnet runtime." -Hidden
204+
Set-PSFConfig -FullName dbops.ErrorActionPreference -Value Stop -Initialize -Description "Module ErrorAction default value" -Validation errorAction
205+
206+
# Module-wide ErrorAction preference
207+
$ErrorActionPreference = Get-PSFConfigValue -FullName dbops.ErrorActionPreference
185208

186209
# extensions for SMO
187210
$typeData = Get-TypeData -TypeName 'Microsoft.SqlServer.Management.Smo.Database'
@@ -220,4 +243,4 @@ $aliases = @(
220243
)
221244
$aliases | ForEach-Object {
222245
if (-not (Test-Path Alias:$($_.AliasName))) { Set-Alias -Scope Global -Name $($_.AliasName) -Value $($_.Definition) }
223-
}
246+
}

docs/changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Release notes for v0.8.1:
2+
- ### Wrapper around dotnet call to filter output (#148) by @nvarscar
3+
# Release notes for v0.8.0:
4+
- ### Hotfix: Nuget downloads now use lowercase filename in the URL (#139) by @nvarscar
5+
- ### Feature: Allow ErrorAction to properly handle errors (#140) by @nvarscar
6+
- ### Setting default encoding to UTF8 (#142) by @nvarscar
17
# Release notes for v0.7.1:
28
- ### Adding support for underscore char in tokens (#130) by @nvarscar
39
# Release notes for v0.7.0:

functions/Invoke-DBOQuery.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ function Invoke-DBOQuery {
435435
}
436436
catch {
437437
# don't really need anything else here
438-
throw $_
438+
Write-Error $_
439439
}
440440
finally {
441441
# close the connection even when interrupted by Ctrl+C

internal/classes/DBOpsDeploymentStatus.class.ps1

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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/Invoke-Deployment.ps1

Lines changed: 5 additions & 2 deletions
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

Lines changed: 3 additions & 0 deletions
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/functional/Install-DBOScript.Tests.ps1

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ Describe "<type> Install-DBOScript functional tests" -Tag FunctionalTests -ForEa
232232
}
233233
}
234234
Context "deployments with errors should throw terminating errors" {
235-
BeforeAll {
235+
BeforeEach {
236236
Reset-TestDatabase
237237
$null = Install-DBOScript -ScriptPath (Get-PackageScript -Version 1) @dbConnectionParams -SchemaVersionTable $null
238238
}
@@ -249,6 +249,22 @@ Describe "<type> Install-DBOScript functional tests" -Tag FunctionalTests -ForEa
249249
$errorObject | Should -Not -BeNullOrEmpty
250250
$errorObject.Exception.Message | Should -BeLike (Get-TableExistsMessage "a")
251251
}
252+
It "Should return failure results with SilentlyContinue" {
253+
$testResults = Install-DBOScript -Path $tranFailScripts -SchemaVersionTable $logTable -DeploymentMethod NoTransaction @dbConnectionParams -ErrorAction SilentlyContinue
254+
$testResults.Successful | Should -Be $false
255+
$testResults.SqlInstance | Should -Be $instance
256+
$testResults.Database | Should -Be $newDbName
257+
$testResults.SourcePath | Should -Be ($tranFailScripts | Split-Path -Leaf)
258+
$testResults.ConnectionType | Should -Be $Type
259+
$testResults.Configuration.SchemaVersionTable | Should -Be $logTable
260+
$testResults.Error.Message | Should -BeLike (Get-TableExistsMessage "a")
261+
$testResults.ErrorScript | Should -Be ($tranFailScripts[1] | Split-Path -Leaf)
262+
$testResults.Scripts.Name | Should -Be ($tranFailScripts[0] | Split-Path -Leaf)
263+
$testResults.Duration.TotalMilliseconds | Should -BeGreaterOrEqual 0
264+
$testResults.StartTime | Should -Not -BeNullOrEmpty
265+
$testResults.EndTime | Should -Not -BeNullOrEmpty
266+
$testResults.EndTime | Should -BeGreaterOrEqual $testResults.StartTime
267+
}
252268
It "should halt after throwing an error" {
253269
#Running package
254270
try {

0 commit comments

Comments
 (0)