Skip to content

Commit 1ab4c3c

Browse files
committed
error handling for ensuring mysql db
1 parent 4863667 commit 1ab4c3c

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

internal/functions/Invoke-EnsureDatabase.ps1

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,24 @@ function Invoke-EnsureDatabase {
1818
return
1919
}
2020
$targetDB = $csBuilder.Database
21-
$csBuilder.Database = 'mysql'
21+
$csBuilder.Database = 'sys'
2222
$dbExistsQuery = "SELECT SCHEMA_NAME AS 'Database' FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '$targetDB'"
23-
$dbExists = Invoke-DBOQuery -Type $Type -ConnectionString $csBuilder -Query $dbExistsQuery
23+
try {
24+
$dbExists = Invoke-DBOQuery -Type $Type -ConnectionString $csBuilder -Query $dbExistsQuery
25+
}
26+
catch {
27+
$Log.WriteError("Unable to check database existance on {0}: {1}", @($csBuilder.Server, $csBuilder.Database));
28+
throw $_
29+
}
2430
if (-not $dbExists.Database) {
2531
$query = 'CREATE DATABASE `{0}`' -f $targetDB
26-
$null = Invoke-DBOQuery -Type $Type -ConnectionString $csBuilder -Query $query
32+
try {
33+
$null = Invoke-DBOQuery -Type $Type -ConnectionString $csBuilder -Query $query
34+
}
35+
catch {
36+
$Log.WriteError("Unable to create database {0} on {1}", @($csBuilder.Database, $csBuilder.Server));
37+
throw $_
38+
}
2739
$Log.WriteInformation("Created database {0}", $targetDB)
2840
}
2941
}

0 commit comments

Comments
 (0)