From 8eeec89ad462bfb749f0405c61f08aebdb298896 Mon Sep 17 00:00:00 2001 From: qcplus <-> Date: Mon, 24 Jul 2023 23:27:17 +1000 Subject: [PATCH 1/2] fixed concat --- Respawn/PostgresDbAdapter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Respawn/PostgresDbAdapter.cs b/Respawn/PostgresDbAdapter.cs index db3a615..2968999 100644 --- a/Respawn/PostgresDbAdapter.cs +++ b/Respawn/PostgresDbAdapter.cs @@ -129,7 +129,7 @@ from INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc { var args = string.Join(",", tableGroup.Tables.Select(table => $"'{table.Schema}.{table.Name}'")); - commandText += " AND tc.TABLE_SCHEMA + '.' + tc.TABLE_NAME NOT IN (" + args + ")"; + commandText += " AND tc.TABLE_SCHEMA || '.' || tc.TABLE_NAME NOT IN (" + args + ")"; } else { @@ -157,7 +157,7 @@ from INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc { var args = string.Join(",", tableGroup.Tables.Select(table => $"'{table.Schema}.{table.Name}'")); - commandText += " AND tc.TABLE_SCHEMA + '.' + tc.TABLE_NAME IN (" + args + ")"; + commandText += " AND tc.TABLE_SCHEMA || '.' || tc.TABLE_NAME IN (" + args + ")"; } else { From 66c96583c768162211c2c387cc61f47becfb72a3 Mon Sep 17 00:00:00 2001 From: qcplus <-> Date: Tue, 25 Jul 2023 20:48:54 +1000 Subject: [PATCH 2/2] tests for postgre with schemas name --- Respawn.DatabaseTests/PostgresTests.cs | 48 ++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/Respawn.DatabaseTests/PostgresTests.cs b/Respawn.DatabaseTests/PostgresTests.cs index 992172b..be8e26d 100644 --- a/Respawn.DatabaseTests/PostgresTests.cs +++ b/Respawn.DatabaseTests/PostgresTests.cs @@ -97,6 +97,30 @@ public async Task ShouldIgnoreTables() _database.ExecuteScalar("SELECT COUNT(1) FROM bar").ShouldBe(0); } + [SkipOnCI] + public async Task ShouldIgnoreTablesIfSchemaSpecified() + { + await _database.ExecuteAsync("create schema eggs"); + await _database.ExecuteAsync("create table eggs.foo (Value int)"); + await _database.ExecuteAsync("create table eggs.bar (Value int)"); + + for (int i = 0; i < 100; i++) + { + await _database.ExecuteAsync("INSERT INTO \"eggs\".\"foo\" VALUES (@0)", i); + await _database.ExecuteAsync("INSERT INTO \"eggs\".\"bar\" VALUES (@0)", i); + } + + var checkpoint = await Respawner.CreateAsync(_connection, new RespawnerOptions + { + DbAdapter = DbAdapter.Postgres, + TablesToIgnore = new Table[] { new Table("eggs", "foo") } + }); + await checkpoint.ResetAsync(_connection); + + _database.ExecuteScalar("SELECT COUNT(1) FROM eggs.foo").ShouldBe(100); + _database.ExecuteScalar("SELECT COUNT(1) FROM eggs.bar").ShouldBe(0); + } + [SkipOnCI] public async Task ShouldIncludeTables() { @@ -120,6 +144,30 @@ public async Task ShouldIncludeTables() _database.ExecuteScalar("SELECT COUNT(1) FROM bar").ShouldBe(100); } + [SkipOnCI] + public async Task ShouldIncludeTablesIfSchemaSpecified() + { + await _database.ExecuteAsync("create schema eggs"); + await _database.ExecuteAsync("create table eggs.foo (Value int)"); + await _database.ExecuteAsync("create table eggs.bar (Value int)"); + + for (int i = 0; i < 100; i++) + { + await _database.ExecuteAsync("INSERT INTO \"eggs\".\"foo\" VALUES (@0)", i); + await _database.ExecuteAsync("INSERT INTO \"eggs\".\"bar\" VALUES (@0)", i); + } + + var checkpoint = await Respawner.CreateAsync(_connection, new RespawnerOptions + { + DbAdapter = DbAdapter.Postgres, + TablesToInclude = new Table[] { new Table("eggs", "foo") } + }); + await checkpoint.ResetAsync(_connection); + + _database.ExecuteScalar("SELECT COUNT(1) FROM eggs.foo").ShouldBe(0); + _database.ExecuteScalar("SELECT COUNT(1) FROM eggs.bar").ShouldBe(100); + } + [SkipOnCI] public async Task ShouldHandleRelationships() {