diff --git a/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyBasicSupport.approved.txt b/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyBasicSupport.approved.txt index ac69b5d..2132e1a 100644 --- a/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyBasicSupport.approved.txt +++ b/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyBasicSupport.approved.txt @@ -1,12 +1,20 @@ DB Operation: Open connection Info: Beginning database upgrade Info: Checking whether journal table exists -DB Operation: Execute scalar command: select 1 from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'schemaversions' +DB Operation: Execute scalar command: +select case + when pg_catalog.to_regclass('"schemaversions"') is not null then 1 + else 0 +end; DB Operation: Dispose command Info: Journal table does not exist Info: Executing Database Server script 'Script0001.sql' Info: Checking whether journal table exists -DB Operation: Execute scalar command: select 1 from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'schemaversions' +DB Operation: Execute scalar command: +select case + when pg_catalog.to_regclass('"schemaversions"') is not null then 1 + else 0 +end; DB Operation: Dispose command Info: Creating the "schemaversions" table DB Operation: Execute non query command: CREATE TABLE "schemaversions" diff --git a/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyJournalCreationIfNameChanged.approved.txt b/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyJournalCreationIfNameChanged.approved.txt index 46bee6c..ed1a276 100644 --- a/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyJournalCreationIfNameChanged.approved.txt +++ b/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyJournalCreationIfNameChanged.approved.txt @@ -1,12 +1,20 @@ DB Operation: Open connection Info: Beginning database upgrade Info: Checking whether journal table exists -DB Operation: Execute scalar command: select 1 from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'TestSchemaVersions' and TABLE_SCHEMA = 'test' +DB Operation: Execute scalar command: +select case + when pg_catalog.to_regclass('"test"."TestSchemaVersions"') is not null then 1 + else 0 +end; DB Operation: Dispose command Info: Journal table does not exist Info: Executing Database Server script 'Script0001.sql' Info: Checking whether journal table exists -DB Operation: Execute scalar command: select 1 from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'TestSchemaVersions' and TABLE_SCHEMA = 'test' +DB Operation: Execute scalar command: +select case + when pg_catalog.to_regclass('"test"."TestSchemaVersions"') is not null then 1 + else 0 +end; DB Operation: Dispose command Info: Creating the "test"."TestSchemaVersions" table DB Operation: Execute non query command: CREATE TABLE "test"."TestSchemaVersions" diff --git a/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyVariableSubstitutions.approved.txt b/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyVariableSubstitutions.approved.txt index 3321b7a..6b59624 100644 --- a/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyVariableSubstitutions.approved.txt +++ b/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyVariableSubstitutions.approved.txt @@ -1,12 +1,20 @@ DB Operation: Open connection Info: Beginning database upgrade Info: Checking whether journal table exists -DB Operation: Execute scalar command: select 1 from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'schemaversions' +DB Operation: Execute scalar command: +select case + when pg_catalog.to_regclass('"schemaversions"') is not null then 1 + else 0 +end; DB Operation: Dispose command Info: Journal table does not exist Info: Executing Database Server script 'Script0001.sql' Info: Checking whether journal table exists -DB Operation: Execute scalar command: select 1 from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'schemaversions' +DB Operation: Execute scalar command: +select case + when pg_catalog.to_regclass('"schemaversions"') is not null then 1 + else 0 +end; DB Operation: Dispose command Info: Creating the "schemaversions" table DB Operation: Execute non query command: CREATE TABLE "schemaversions" diff --git a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs b/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs index b3131dc..2ab976e 100644 --- a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs +++ b/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs @@ -63,6 +63,7 @@ public class PostgresqlTableJournal : DbUp.Support.TableJournal { public PostgresqlTableJournal(System.Func connectionManager, System.Func logger, string schema, string tableName) { } protected override string CreateSchemaTableSql(string quotedPrimaryKeyName) { } + protected override string DoesTableExistSql() { } protected override string GetInsertJournalEntrySql(string scriptName, string applied) { } protected override System.Data.IDbCommand GetInsertScriptCommand(System.Func dbCommandFactory, DbUp.Engine.SqlScript script) { } protected override string GetJournalEntriesSql() { } diff --git a/src/dbup-postgresql/PostgresqlTableJournal.cs b/src/dbup-postgresql/PostgresqlTableJournal.cs index 1fe0e0f..e76616f 100644 --- a/src/dbup-postgresql/PostgresqlTableJournal.cs +++ b/src/dbup-postgresql/PostgresqlTableJournal.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Data; using DbUp.Engine; using DbUp.Engine.Output; @@ -74,4 +74,18 @@ scriptname character varying(255) NOT NULL, CONSTRAINT {quotedPrimaryKeyName} PRIMARY KEY (schemaversionsid) )"; } -} \ No newline at end of file + + /// + protected override string DoesTableExistSql() + { + string fqSchemaTableName = FqSchemaTableName.Replace("'", "''"); + + string sql = $@" +select case + when pg_catalog.to_regclass('{fqSchemaTableName}') is not null then 1 + else 0 +end;"; + + return sql; + } +}