Skip to content

Commit 7044ec4

Browse files
committed
Using enums in parameters now
1 parent 7074f17 commit 7044ec4

18 files changed

+73
-70
lines changed

bin/deploy.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ $config = Get-DBOConfig -Path "$PSScriptRoot\dbops.config.json" -Configuration $
4141

4242
#Convert custom parameters into a package configuration, excluding variables
4343
foreach ($key in ($PSBoundParameters.Keys)) {
44-
if ($key -in [DBOpsConfigProperty].GetEnumNames() -and $key -ne 'Variables') {
44+
if ($key -in [DBOps.ConfigProperty].GetEnumNames() -and $key -ne 'Variables') {
4545
Write-PSFMessage -Level Debug -Message "Overriding parameter $key with $($PSBoundParameters[$key])"
4646
$config.SetValue($key, $PSBoundParameters[$key])
4747
}

functions/Install-DBOPackage.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,8 @@
166166
[switch]$CreateDatabase,
167167
[AllowNull()]
168168
[string]$ConnectionString,
169-
[ValidateSet('SQLServer', 'Oracle')]
170169
[Alias('ConnectionType', 'ServerType')]
171-
[string]$Type = (Get-DBODefaultSetting -Name rdbms.type -Value)
170+
[DBOps.ConnectionType]$Type = (Get-DBODefaultSetting -Name rdbms.type -Value)
172171
)
173172

174173
begin {

functions/Install-DBOSqlScript.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,8 @@
162162
[switch]$CreateDatabase,
163163
[AllowNull()]
164164
[string]$ConnectionString,
165-
[ValidateSet('SQLServer', 'Oracle')]
166165
[Alias('ConnectionType', 'ServerType')]
167-
[string]$Type = (Get-DBODefaultSetting -Name rdbms.type -Value)
166+
[DBOps.ConnectionType]$Type = (Get-DBODefaultSetting -Name rdbms.type -Value)
168167
)
169168

170169
begin {

functions/Install-DBOSupportLibrary.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ Function Install-DBOSupportLibrary {
3434
ValueFromPipeline = $true,
3535
Position = 1)]
3636
[Alias('System', 'Database')]
37-
[ValidateSet('SQLServer', 'Oracle')]
38-
[string[]]$Type,
37+
[DBOps.ConnectionType[]]$Type,
3938
[ValidateSet('CurrentUser', 'AllUsers')]
4039
[string]$Scope = 'AllUsers',
4140
[switch]$Force

functions/Invoke-DBODeployment.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,8 @@
8282
[string[]]$Build,
8383
[string]$OutputFile,
8484
[switch]$Append,
85-
[ValidateSet('SQLServer', 'Oracle')]
8685
[Alias('ConnectionType', 'ServerType')]
87-
[string]$Type = (Get-DBODefaultSetting -Name rdbms.type -Value),
86+
[DBOps.ConnectionType]$Type = (Get-DBODefaultSetting -Name rdbms.type -Value),
8887
[object]$Configuration,
8988
[switch]$RegisterOnly
9089
)

functions/Invoke-DBOQuery.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,8 @@ function Invoke-DBOQuery {
141141
[string]$Schema,
142142
[AllowNull()]
143143
[string]$ConnectionString,
144-
[ValidateSet('SQLServer', 'Oracle')]
145144
[Alias('ConnectionType', 'ServerType')]
146-
[string]$Type = (Get-DBODefaultSetting -Name rdbms.type -Value),
145+
[DBOps.ConnectionType]$Type = (Get-DBODefaultSetting -Name rdbms.type -Value),
147146
[ValidateSet("DataSet", "DataTable", "DataRow", "PSObject", "SingleValue")]
148147
[string]
149148
$As = "DataRow",

functions/Test-DBOSupportedSystem.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ Function Test-DBOSupportedSystem {
2020
ValueFromPipeline = $true,
2121
Position = 1)]
2222
[Alias('System', 'Database')]
23-
[ValidateSet('SQLServer', 'Oracle')]
24-
[string]$Type
23+
[DBOps.ConnectionType]$Type
2524
)
2625
begin {}
2726
process {

functions/Update-DBOConfig.ps1

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,33 @@
22
<#
33
.SYNOPSIS
44
Updates configuration file inside the existing DBOps package
5-
5+
66
.DESCRIPTION
77
Overwrites configuration file inside the existing DBOps package with the new values provided by user
8-
8+
99
.PARAMETER Path
1010
Path to the existing DBOpsPackage.
1111
Aliases: Name, FileName, Package
12-
12+
1313
.PARAMETER ConfigurationFile
1414
A path to the custom configuration json file
1515
Alias: ConfigFile
16-
16+
1717
.PARAMETER Configuration
1818
Object containing several configuration items at once
1919
Alias: Config
20-
20+
2121
.PARAMETER ConfigName
2222
Name of the configuration item to update
23-
23+
2424
.PARAMETER Value
2525
Value of the parameter specified in -ConfigName
2626
2727
.PARAMETER Variables
2828
Hashtable with variables that can be used inside the scripts and deployment parameters.
2929
Proper format of the variable tokens is #{MyVariableName}
3030
Can also be provided as a part of Configuration Object: -Configuration @{ Variables = @{ Var1 = ...; Var2 = ...}}
31-
31+
3232
.PARAMETER Confirm
3333
Prompts to confirm certain actions
3434
@@ -46,11 +46,11 @@
4646
.EXAMPLE
4747
# Update parameters based on the contents of the json file myconfig.json
4848
Update-DBOConfig Package.zip -ConfigurationFile 'myconfig.json'
49-
49+
5050
.EXAMPLE
5151
# Specifically update values of the Variables parameter
5252
Update-DBOConfig Package.zip -Variables @{ foo = 'bar' }
53-
53+
5454
#>
5555
[CmdletBinding(DefaultParameterSetName = 'Value',
5656
SupportsShouldProcess)]
@@ -63,11 +63,7 @@
6363
[Parameter(ParameterSetName = 'Value',
6464
Mandatory = $true,
6565
Position = 2 )]
66-
[ValidateSet('ApplicationName', 'SqlInstance', 'Database', 'DeploymentMethod',
67-
'ConnectionTimeout', 'ExecutionTimeout', 'Encrypt', 'Credential', 'Username',
68-
'Password', 'SchemaVersionTable', 'Silent', 'Variables'
69-
)]
70-
[string]$ConfigName,
66+
[DBOps.ConfigProperty]$ConfigName,
7167
[Parameter(ParameterSetName = 'Value',
7268
Mandatory = $true,
7369
Position = 3 )]

internal/classes/DBOps.class.ps1

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ class DBOps {
2727
hidden [void] WriteVerbose ([string]$Message, [object]$Target) {
2828
$callStack = (Get-PSCallStack)[1]
2929
$splatParam = @{
30-
Tag = 'DBOps', 'class', $this.GetType().Name
31-
FunctionName = $this.GetType().Name
32-
ModuleName = 'dbops'
33-
File = $callStack.Position.File
34-
Line = $callStack.Position.StartLineNumber
35-
Message = $Message
36-
Target = $Target
37-
Level = 'Verbose'
30+
Tag = 'DBOps', 'class', $this.GetType().Name
31+
FunctionName = $this.GetType().Name
32+
ModuleName = 'dbops'
33+
File = $callStack.Position.File
34+
Line = $callStack.Position.StartLineNumber
35+
Message = $Message
36+
Target = $Target
37+
Level = 'Verbose'
3838
}
3939
Write-PSFMessage @splatParam
4040
}
@@ -99,7 +99,7 @@ class DBOps {
9999
hidden [void] RemoveFile ([string[]]$PackagePath, [string]$CollectionName) {
100100
if ($this.$CollectionName) {
101101
foreach ($path in $PackagePath) {
102-
$this.RemoveFile($this.$CollectionName.GetFile($path, $CollectionName),$CollectionName)
102+
$this.RemoveFile($this.$CollectionName.GetFile($path, $CollectionName), $CollectionName)
103103
}
104104
}
105105
}
@@ -1061,7 +1061,7 @@ class DBOpsScriptFile : DBOpsFile {
10611061
$lastParent = $lastParent.Parent
10621062
}
10631063
$dPath = $dPath -replace ('^' + [regex]::Escape($lastParent.GetPackagePath() + ([IO.Path]::DirectorySeparatorChar))), ''
1064-
return $dPath.Replace('/','\')
1064+
return $dPath.Replace('/', '\')
10651065
}
10661066
}
10671067

@@ -1172,7 +1172,8 @@ class DBOpsConfig : DBOps {
11721172
}
11731173
}
11741174
}
1175-
else { $outObject += @{ $prop = $this.$prop }}
1175+
else { $outObject += @{ $prop = $this.$prop }
1176+
}
11761177
}
11771178
return $outObject | ConvertTo-Json -Depth 3
11781179
}
@@ -1278,7 +1279,7 @@ class DBOpsConfig : DBOps {
12781279
}
12791280

12801281
static [string[]] EnumProperties () {
1281-
return [DBOpsConfigProperty].GetEnumNames()
1282+
return [DBOps.ConfigProperty].GetEnumNames()
12821283
}
12831284

12841285
#Returns deploy file name

internal/classes/DBOps.enums.ps1

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1-
enum DBOpsConnectionType {
2-
SQLServer
3-
Oracle
1+
$enums = @'
2+
namespace DBOps {
3+
public enum ConnectionType {
4+
SQLServer,
5+
Oracle
6+
}
7+
public enum ConfigProperty {
8+
ApplicationName,
9+
SqlInstance,
10+
Database,
11+
DeploymentMethod,
12+
ConnectionTimeout,
13+
ExecutionTimeout,
14+
Encrypt,
15+
Credential,
16+
Username,
17+
Password,
18+
SchemaVersionTable,
19+
Silent,
20+
Variables,
21+
Schema,
22+
ConnectionString,
23+
CreateDatabase,
24+
}
425
}
5-
enum DBOpsConfigProperty {
6-
ApplicationName
7-
SqlInstance
8-
Database
9-
DeploymentMethod
10-
ConnectionTimeout
11-
ExecutionTimeout
12-
Encrypt
13-
Credential
14-
Username
15-
Password
16-
SchemaVersionTable
17-
Silent
18-
Variables
19-
Schema
20-
ConnectionString
21-
CreateDatabase
22-
}
26+
'@
27+
Add-Type -TypeDefinition $enums -ErrorAction Stop

0 commit comments

Comments
 (0)