diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2024-08-18 16:06:54 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-18 16:06:54 -0400 |
| commit | 3ad5a6ab1ef53330f18014b710534d0ed0cd55b0 (patch) | |
| tree | 5b5d1ed42e59314e65a4ddb8bff2dd7c059fedd9 /internal/repositories | |
| parent | Add a couple helper scripts (diff) | |
| download | cli-3ad5a6ab1ef53330f18014b710534d0ed0cd55b0.zip | |
Fix using a schema with a custom migration table name (#7)
* Fix using a schema with a custom migration table name
* Fix test
Diffstat (limited to 'internal/repositories')
| -rw-r--r-- | internal/repositories/migration_db_repo_mssql_test.go | 38 | ||||
| -rw-r--r-- | internal/repositories/migration_db_repo_postgresql_test.go | 36 |
2 files changed, 74 insertions, 0 deletions
diff --git a/internal/repositories/migration_db_repo_mssql_test.go b/internal/repositories/migration_db_repo_mssql_test.go new file mode 100644 index 0000000..5c79168 --- /dev/null +++ b/internal/repositories/migration_db_repo_mssql_test.go @@ -0,0 +1,38 @@ +//go:build mssql + +package repositories_test + +import ( + "testing" + + "github.com/eugenetriguba/bolt/internal/bolttest" + "github.com/eugenetriguba/bolt/internal/repositories" + "github.com/eugenetriguba/checkmate/assert" +) + +func TestNewMigrationDBRepo_CreatesTableInSchema_MSSQL(t *testing.T) { + testdb := bolttest.NewTestDB(t) + schemaName := "custom_schema" + tableName := schemaName + ".bolt_migrations" + + t.Cleanup(func() { + _, err := testdb.Exec("DROP TABLE IF EXISTS " + tableName) + assert.Nil(t, err) + _, err = testdb.Exec("DROP SCHEMA IF EXISTS " + schemaName) + assert.Nil(t, err) + }) + + _, err := testdb.Exec("CREATE SCHEMA " + schemaName) + assert.Nil(t, err) + + exists, err := testdb.TableExists(tableName) + assert.Nil(t, err) + assert.False(t, exists) + + _, err = repositories.NewMigrationDBRepo(tableName, testdb) + assert.Nil(t, err) + + exists, err = testdb.TableExists(tableName) + assert.Nil(t, err) + assert.True(t, exists) +} diff --git a/internal/repositories/migration_db_repo_postgresql_test.go b/internal/repositories/migration_db_repo_postgresql_test.go new file mode 100644 index 0000000..0df9c1d --- /dev/null +++ b/internal/repositories/migration_db_repo_postgresql_test.go @@ -0,0 +1,36 @@ +//go:build postgresql + +package repositories_test + +import ( + "testing" + + "github.com/eugenetriguba/bolt/internal/bolttest" + "github.com/eugenetriguba/bolt/internal/repositories" + "github.com/eugenetriguba/checkmate/assert" +) + +func TestNewMigrationDBRepo_CreatesTableInSchema_Postgresql(t *testing.T) { + testdb := bolttest.NewTestDB(t) + schemaName := "custom_schema" + tableName := schemaName + ".bolt_migrations" + + t.Cleanup(func() { + _, err := testdb.Exec("DROP SCHEMA IF EXISTS " + schemaName + " CASCADE;") + assert.Nil(t, err) + }) + + _, err := testdb.Exec("CREATE SCHEMA IF NOT EXISTS " + schemaName) + assert.Nil(t, err) + + exists, err := testdb.TableExists(tableName) + assert.Nil(t, err) + assert.False(t, exists) + + _, err = repositories.NewMigrationDBRepo(tableName, testdb) + assert.Nil(t, err) + + exists, err = testdb.TableExists(tableName) + assert.Nil(t, err) + assert.True(t, exists) +} |