From 3ad5a6ab1ef53330f18014b710534d0ed0cd55b0 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 18 Aug 2024 16:06:54 -0400 Subject: Fix using a schema with a custom migration table name (#7) * Fix using a schema with a custom migration table name * Fix test --- internal/storage/postgresql_test.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'internal/storage/postgresql_test.go') diff --git a/internal/storage/postgresql_test.go b/internal/storage/postgresql_test.go index ef89cff..d244646 100644 --- a/internal/storage/postgresql_test.go +++ b/internal/storage/postgresql_test.go @@ -44,7 +44,7 @@ func TestPostgresql_ConvertGenericPlaceholders(t *testing.T) { } } -func TestPostgresql_TableExists(t *testing.T) { +func TestPostgresql_TableExistsDefaultSchema(t *testing.T) { cfg := bolttest.NewTestConnectionConfig() adapter := storage.PostgresqlAdapter{} db, err := sql.Open("pgx", adapter.CreateDSN(cfg)) @@ -67,6 +67,32 @@ func TestPostgresql_TableExists(t *testing.T) { assert.True(t, exists) } +func TestPostgresql_TableExistsCustomSchema(t *testing.T) { + cfg := bolttest.NewTestConnectionConfig() + adapter := storage.PostgresqlAdapter{} + db, err := sql.Open("pgx", adapter.CreateDSN(cfg)) + assert.Nil(t, err) + t.Cleanup(func() { + _, err = db.Exec("DROP SCHEMA IF EXISTS custom_schema CASCADE;") + assert.Nil(t, err) + assert.Nil(t, db.Close()) + }) + + exists, err := adapter.TableExists(db, "custom_table.tmp") + assert.Nil(t, err) + assert.False(t, exists) + + _, err = db.Exec("CREATE SCHEMA custom_schema;") + assert.Nil(t, err) + + _, err = db.Exec("CREATE TABLE custom_schema.tmp(id INT PRIMARY KEY);") + assert.Nil(t, err) + + exists, err = adapter.TableExists(db, "custom_schema.tmp") + assert.Nil(t, err) + assert.True(t, exists) +} + func TestPostgresql_DatabaseName(t *testing.T) { cfg := bolttest.NewTestConnectionConfig() adapter := storage.PostgresqlAdapter{} -- cgit v1.2.3