Skip to content

Commit 4863667

Browse files
committed
Using inherited class instead of workarounds - journals
1 parent d1500ca commit 4863667

File tree

7 files changed

+103
-99
lines changed

7 files changed

+103
-99
lines changed

functions/Invoke-DBODeployment.ps1

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,6 @@
159159
$connString = $csBuilder.ToString()
160160
$dbUpConnection = Get-ConnectionManager -ConnectionString $connString -Type $Type
161161

162-
# MySQL workaround: define schema if not specified, bc schema = database
163-
if ($Type -eq 'MySQL' -and -not $config.Schema) {
164-
$config.SetValue('Schema', $csBuilder.Database)
165-
}
166-
167162
# Create DbUpBuilder based on the connection
168163
$dbUp = Get-DbUpBuilder -Connection $dbUpConnection -Type $Type
169164

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class DBOpsMySqlTableJournal : DbUp.MySql.MySqlTableJournal {
2+
# Constructors
3+
DBOpsMySqlTableJournal([Func[DbUp.Engine.Transactions.IConnectionManager]] $connectionManager, [Func[DbUp.Engine.Output.IUpgradeLog]] $logger, [string] $schema, [string] $table) :base($connectionManager, $logger, $schema, $table) {}
4+
# Overriding DoesTalbeExist method to get the proper schema table when schemaversiontable name is not specified
5+
[string] DoesTableExistSql() {
6+
if ($this.SchemaTableSchema) {
7+
return "select 1 from INFORMATION_SCHEMA.TABLES where TABLE_NAME = '{0}' and TABLE_SCHEMA = '{1}'" -f $this.UnquotedSchemaTableName, $this.SchemaTableSchema
8+
}
9+
else {
10+
return "select 1 from INFORMATION_SCHEMA.TABLES where TABLE_NAME = '{0}' and TABLE_SCHEMA = DATABASE()" -f $this.UnquotedSchemaTableName
11+
}
12+
}
13+
}

internal/functions/Get-DbUpJournal.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function Get-DbUpJournal {
3737
$dbUpJournalType = [DbUp.Oracle.OracleTableJournal]
3838
}
3939
elseif ($Type -eq [DBOps.ConnectionType]::MySQL) {
40-
$dbUpJournalType = [DbUp.MySql.MySqlTableJournal]
40+
$dbUpJournalType = [DBOpsMySqlTableJournal]
4141
}
4242
elseif ($Type -eq [DBOps.ConnectionType]::PostgreSQL) {
4343
$dbUpJournalType = [DbUp.Postgresql.PostgresqlTableJournal]

internal/json/dbops.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
"internal\\classes\\DBOps.class.ps1",
6161
"internal\\classes\\DBOpsDeploymentStatus.class.ps1",
6262
"internal\\classes\\DBOpsLog.class.ps1",
63-
"internal\\classes\\DBOpsScriptComparer.class.ps1"
63+
"internal\\classes\\DBOpsScriptComparer.class.ps1",
64+
"internal\\classes\\DBOpsMySqlTableJournal.class.ps1"
6465
],
6566
"Core": [
6667
"internal\\json\\dbops.json",

tests/mysql/Install-DBOPackage.Tests.ps1

Lines changed: 80 additions & 85 deletions
Large diffs are not rendered by default.

tests/mysql/Install-DBOSqlScript.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ Describe "Install-DBOSqlScript MySQL integration tests" -Tag $commandName, Integ
201201
'd' | Should BeIn $testResults.name
202202
#Verifying order
203203
$r1 = Invoke-DBOQuery -Type MySQL -SqlInstance $script:mysqlInstance -Silent -Credential $script:mysqlCredential -Database $newDbName -Query "SELECT scriptname FROM $logtable ORDER BY schemaversionid"
204-
$r1.ScriptName | Should Be (Get-Item $v2scripts, $v1scripts).FullName
204+
$r1.scriptname | Should Be (Get-Item $v2scripts, $v1scripts).FullName
205205
}
206206
}
207207
Context "testing timeouts" {

tests/mysql/Register-DBOPackage.Tests.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ Describe "Register-DBOPackage MySQL integration tests" -Tag $commandName, Integr
7575
'd' | Should Not BeIn $testResults.name
7676

7777
#Verifying SchemaVersions table
78-
$testResults = Invoke-DBOQuery -Type MySQL -SqlInstance $script:mysqlInstance -Silent -Credential $script:mysqlCredential -Database $newDbName -Query "SELECT * FROM $logTable"
79-
$testResults.ScriptName | Should Be (@($v1Journal) + @($v2Journal))
78+
$testResults = Invoke-DBOQuery -Type MySQL -SqlInstance $script:mysqlInstance -Silent -Credential $script:mysqlCredential -Database $newDbName -Query "SELECT * FROM $logTable ORDER BY schemaversionid"
79+
$testResults.scriptname | Should Be (@($v1Journal) + @($v2Journal))
8080
}
8181
}
8282
Context "testing registration of scripts" {
@@ -114,8 +114,8 @@ Describe "Register-DBOPackage MySQL integration tests" -Tag $commandName, Integr
114114
($testResults | Measure-Object).Count | Should Be ($rowsBefore + 1)
115115

116116
#Verifying SchemaVersions table
117-
$testResults = Invoke-DBOQuery -Type MySQL -SqlInstance $script:mysqlInstance -Silent -Credential $script:mysqlCredential -Database $newDbName -Query "SELECT * FROM $logTable"
118-
$testResults.ScriptName | Should Be $v1Journal
117+
$testResults = Invoke-DBOQuery -Type MySQL -SqlInstance $script:mysqlInstance -Silent -Credential $script:mysqlCredential -Database $newDbName -Query "SELECT * FROM $logTable ORDER BY schemaversionid"
118+
$testResults.scriptname | Should Be $v1Journal
119119
}
120120
It "should register version 1.0 + 2.0 without creating any objects" {
121121
$before = Invoke-DBOQuery -Type MySQL -SqlInstance $script:mysqlInstance -Silent -Credential $script:mysqlCredential -Database $newDbName -InputFile $verificationScript
@@ -145,8 +145,8 @@ Describe "Register-DBOPackage MySQL integration tests" -Tag $commandName, Integr
145145
($testResults | Measure-Object).Count | Should Be $rowsBefore
146146

147147
#Verifying SchemaVersions table
148-
$testResults = Invoke-DBOQuery -Type MySQL -SqlInstance $script:mysqlInstance -Silent -Credential $script:mysqlCredential -Database $newDbName -Query "SELECT * FROM $logTable"
149-
$testResults.ScriptName | Should Be (@($v1Journal) + @($v2Journal))
148+
$testResults = Invoke-DBOQuery -Type MySQL -SqlInstance $script:mysqlInstance -Silent -Credential $script:mysqlCredential -Database $newDbName -Query "SELECT * FROM $logTable ORDER BY schemaversionid"
149+
$testResults.scriptname | Should Be (@($v1Journal) + @($v2Journal))
150150
}
151151
}
152152
Context "$commandName whatif tests" {

0 commit comments

Comments
 (0)