aboutsummaryrefslogtreecommitdiffstats
path: root/internal/repositories
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2024-03-11 18:56:21 -0400
committerEugene Triguba <eugenetriguba@gmail.com>2024-03-11 18:56:21 -0400
commit58cc6cdbe0a0553a8e4319de12132e82d8bb85df (patch)
treea17b8cdbaf74797dc4f52e006635e4f5c9a210c2 /internal/repositories
parentTweak tests (diff)
downloadcli-58cc6cdbe0a0553a8e4319de12132e82d8bb85df.zip
Add support for sql server
Diffstat (limited to 'internal/repositories')
-rw-r--r--internal/repositories/migration_db_repo.go22
-rw-r--r--internal/repositories/migration_db_repo_test.go1
2 files changed, 17 insertions, 6 deletions
diff --git a/internal/repositories/migration_db_repo.go b/internal/repositories/migration_db_repo.go
index 27644ae..e97349a 100644
--- a/internal/repositories/migration_db_repo.go
+++ b/internal/repositories/migration_db_repo.go
@@ -28,18 +28,28 @@ type migrationDBRepo struct {
// operates on exists. If it is unable to create or confirm
// the table exists, an error is returned.
func NewMigrationDBRepo(db storage.DB) (MigrationDBRepo, error) {
- _, err := db.Exec(`
- CREATE TABLE IF NOT EXISTS bolt_migrations(
- version CHARACTER(14) PRIMARY KEY NOT NULL
- );
- `)
+ migrationTableExists, err := db.TableExists("bolt_migrations")
if err != nil {
return nil, fmt.Errorf(
- "unable to create or confirm bolt_migrations database table exists: %w",
+ "unable to confirm bolt_migrations database table exists: %w",
err,
)
}
+ if !migrationTableExists {
+ _, err := db.Exec(`
+ CREATE TABLE bolt_migrations(
+ version CHARACTER(14) PRIMARY KEY NOT NULL
+ );
+ `)
+ if err != nil {
+ return nil, fmt.Errorf(
+ "unable to create bolt_migrations database table: %w",
+ err,
+ )
+ }
+ }
+
return &migrationDBRepo{db: db}, nil
}
diff --git a/internal/repositories/migration_db_repo_test.go b/internal/repositories/migration_db_repo_test.go
index 2a316c9..9c5d824 100644
--- a/internal/repositories/migration_db_repo_test.go
+++ b/internal/repositories/migration_db_repo_test.go
@@ -245,6 +245,7 @@ func TestRevertWithTx_SuccessfullyReverted(t *testing.T) {
t.Cleanup(func() {
bolttest.DropTable(t, testdb, "tmp")
})
+ bolttest.DropTable(t, testdb, "tmp")
_, err = testdb.Exec(`CREATE TABLE tmp(id INT NOT NULL PRIMARY KEY)`)
assert.Nil(t, err)