Skip to content

Commit a85e119

Browse files
committed
Adding support for psql and mysql
1 parent 7a9c0f9 commit a85e119

17 files changed

+115
-36
lines changed

bin/dbup-mysql.dll

12.5 KB
Binary file not shown.

bin/dbup-postgresql.dll

13 KB
Binary file not shown.

dbops.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Set-PSFConfig -FullName dbops.mail.To -Value "" -Initialize -Description "'To' f
146146
Set-PSFConfig -FullName dbops.mail.Subject -Value "DBOps deployment status" -Initialize -Description "'Subject' field in the outgoing emails."
147147
Set-PSFConfig -FullName dbops.security.encryptionkey -Value "~/.dbops.key" -Initialize -Description "Path to a custom encryption key used to encrypt/decrypt passwords. The key should be a binary file with a length of 128, 192 or 256 bits. Key will be generated automatically if not exists."
148148
Set-PSFConfig -FullName dbops.security.usecustomencryptionkey -Value ($PSVersionTable.Platform -eq 'Unix') -Validation bool -Initialize -Description "Determines whether to use a custom encryption key for storing passwords. Enabled by default only on Unix platforms."
149-
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"
149+
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"
150150

151151
# extensions for SMO
152152
$typeData = Get-TypeData -TypeName 'Microsoft.SqlServer.Management.Smo.Database'

functions/Invoke-DBODeployment.ps1

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,11 @@
154154
}
155155

156156
Write-PSFMessage -Level Debug -Message "Creating DbUp objects"
157-
# Get DbUp connection object
158-
$dbUpConnection = Get-ConnectionManager -Configuration $config -Type $Type
157+
# Create DbUp connection object
158+
$connString = Get-ConnectionString -Configuration $config -Type $Type
159+
$dbUpConnection = Get-ConnectionManager -ConnectionString $connString -Type $Type
159160

160-
# Get DbUpBuilder based on the connection
161+
# Create DbUpBuilder based on the connection
161162
$dbUp = Get-DbUpBuilder -Connection $dbUpConnection -Type $Type
162163

163164
# Add deployment scripts to the object
@@ -209,9 +210,7 @@
209210
if ($config.CreateDatabase) {
210211
if ($PSCmdlet.ShouldProcess("Ensuring the target database exists")) {
211212
Write-PSFMessage -Level Debug -Message "Creating database if not exists"
212-
switch ($Type) {
213-
SqlServer { [SqlServerExtensions]::SqlDatabase([DbUp.EnsureDatabase]::For, $connString, $dbUpLog, $config.ExecutionTimeout) }
214-
}
213+
$null = Invoke-EnsureDatabase -ConnectionString $connString -Log $dbUpLog -Timeout $config.ExecutionTimeout -Type $Type
215214
}
216215
}
217216
# Register only

functions/Invoke-DBOQuery.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function Invoke-DBOQuery {
204204
}
205205
}
206206
catch {
207-
Stop-PSFFunction -Message 'File not found' -Exception $_ -EnableException $true
207+
Stop-PSFFunction -Message 'File not found' -ErrorRecord $_ -EnableException $true
208208
}
209209
$queryText = $fileObjects | Get-Content -Raw
210210
}

internal/classes/DBOps.enums.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
$enums = @'
22
namespace DBOps {
33
public enum ConnectionType {
4-
SQLServer,
4+
SqlServer,
55
Oracle,
6-
MySql
6+
MySQL,
7+
PostgreSQL
78
}
89
public enum ConfigProperty {
910
ApplicationName,

internal/functions/Get-ConnectionManager.ps1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ function Get-ConnectionManager {
1010
if ($Configuration) {
1111
$ConnectionString = Get-ConnectionString -Configuration $Configuration -Type $Type
1212
}
13-
if ($Type -eq 'SqlServer') {
13+
if ($Type -eq [DBOps.ConnectionType]::SqlServer) {
1414
return [DbUp.SqlServer.SqlConnectionManager]::new($ConnectionString)
1515
}
16-
elseif ($Type -eq 'Oracle') {
16+
elseif ($Type -eq [DBOps.ConnectionType]::Oracle) {
1717
return [DbUp.Oracle.OracleConnectionManager]::new($ConnectionString)
1818
}
19-
elseif ($Type -eq 'MySql') {
19+
elseif ($Type -eq [DBOps.ConnectionType]::MySQL) {
2020
return [DbUp.MySql.MySqlConnectionManager]::new($ConnectionString)
2121
}
22+
elseif ($Type -eq [DBOps.ConnectionType]::PostgreSQL) {
23+
return [DbUp.Postgresql.PostgresqlConnectionManager]::new($ConnectionString)
24+
}
2225
else {
2326
Stop-PSFFunction -Message "Unknown type $Type" -EnableException $true
2427
return

internal/functions/Get-DbUpBuilder.ps1

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,30 @@ function Get-DbUpBuilder {
2323
$dbUp = [DbUp.Oracle.OracleExtensions]::OracleDatabase($dbUp, $dbUpConnection)
2424
}
2525
}
26-
elseif ($Type -eq [DBOps.ConnectionType]::MySql) {
26+
elseif ($Type -eq [DBOps.ConnectionType]::MySQL) {
2727
if ($Schema) {
2828
$dbUp = [MySqlExtensions]::MySqlDatabase($dbUp, $dbUpConnection, $Schema)
2929
}
3030
else {
3131
$dbUp = [MySqlExtensions]::MySqlDatabase($dbUp, $dbUpConnection)
3232
}
3333
}
34+
elseif ($Type -eq [DBOps.ConnectionType]::MySQL) {
35+
if ($Schema) {
36+
$dbUp = [MySqlExtensions]::MySqlDatabase($dbUp, $dbUpConnection, $Schema)
37+
}
38+
else {
39+
$dbUp = [MySqlExtensions]::MySqlDatabase($dbUp, $dbUpConnection)
40+
}
41+
}
42+
elseif ($Type -eq [DBOps.ConnectionType]::PostgreSQL) {
43+
if ($Schema) {
44+
$dbUp = [PostgresqlExtensions]::PostgresqlDatabase($dbUp, $dbUpConnection, $Schema)
45+
}
46+
else {
47+
$dbUp = [PostgresqlExtensions]::PostgresqlDatabase($dbUp, $dbUpConnection)
48+
}
49+
}
3450
else {
3551
Stop-PSFFunction -Message "Unknown type $Type" -EnableException $true
3652
return

internal/functions/Get-DbUpJournal.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ function Get-DbUpJournal {
3636
elseif ($Type -eq [DBOps.ConnectionType]::Oracle) {
3737
$dbUpJournalType = [DbUp.Oracle.OracleTableJournal]
3838
}
39-
elseif ($Type -eq [DBOps.ConnectionType]::MySql) {
39+
elseif ($Type -eq [DBOps.ConnectionType]::MySQL) {
4040
$dbUpJournalType = [DbUp.MySql.MySqlTableJournal]
4141
}
42+
elseif ($Type -eq [DBOps.ConnectionType]::PostgreSQL) {
43+
$dbUpJournalType = [DbUp.Postgresql.PostgresqlTableJournal]
44+
}
4245
else {
4346
Stop-PSFFunction -Message "Unknown type $Type" -EnableException $true
4447
return

internal/functions/Get-SqlParser.ps1

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@ function Get-SqlParser {
44
[Parameter(Mandatory)]
55
[DBOps.ConnectionType]$Type
66
)
7-
if ($Type -eq 'SqlServer') {
7+
if ($Type -eq [DBOps.ConnectionType]::SqlServer) {
88
return [DbUp.SqlServer.SqlServerObjectParser]::new()
99
}
10-
elseif ($Type -eq 'Oracle') {
10+
elseif ($Type -eq [DBOps.ConnectionType]::Oracle) {
1111
return [DbUp.Oracle.OracleObjectParser]::new()
1212
}
13-
elseif ($Type -eq 'MySql') {
13+
elseif ($Type -eq [DBOps.ConnectionType]::MySQL) {
1414
return [DbUp.MySql.MySqlObjectParser]::new()
1515
}
16+
elseif ($Type -eq [DBOps.ConnectionType]::PostgreSQL) {
17+
return [DbUp.Postgresql.PostgresqlObjectParser]::new()
18+
}
19+
else {
20+
Stop-PSFFunction -Message "Unknown type $Type" -EnableException $true
21+
return
22+
}
1623
}

0 commit comments

Comments
 (0)