Skip to content

Commit

Permalink
Merge pull request #125 from QCplus/master
Browse files Browse the repository at this point in the history
fixed concat
  • Loading branch information
jbogard authored Oct 16, 2023
2 parents 6bb39d4 + 66c9658 commit d07ad07
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
48 changes: 48 additions & 0 deletions Respawn.DatabaseTests/PostgresTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,30 @@ public async Task ShouldIgnoreTables()
_database.ExecuteScalar<int>("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<int>("SELECT COUNT(1) FROM eggs.foo").ShouldBe(100);
_database.ExecuteScalar<int>("SELECT COUNT(1) FROM eggs.bar").ShouldBe(0);
}

[SkipOnCI]
public async Task ShouldIncludeTables()
{
Expand All @@ -120,6 +144,30 @@ public async Task ShouldIncludeTables()
_database.ExecuteScalar<int>("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<int>("SELECT COUNT(1) FROM eggs.foo").ShouldBe(0);
_database.ExecuteScalar<int>("SELECT COUNT(1) FROM eggs.bar").ShouldBe(100);
}

[SkipOnCI]
public async Task ShouldHandleRelationships()
{
Expand Down
4 changes: 2 additions & 2 deletions Respawn/PostgresDbAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit d07ad07

Please sign in to comment.