diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2024-03-11 18:56:21 -0400 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2024-03-11 18:56:21 -0400 |
| commit | 58cc6cdbe0a0553a8e4319de12132e82d8bb85df (patch) | |
| tree | a17b8cdbaf74797dc4f52e006635e4f5c9a210c2 /internal/repositories/migration_db_repo.go | |
| parent | Tweak tests (diff) | |
| download | cli-58cc6cdbe0a0553a8e4319de12132e82d8bb85df.zip | |
Add support for sql server
Diffstat (limited to 'internal/repositories/migration_db_repo.go')
| -rw-r--r-- | internal/repositories/migration_db_repo.go | 22 |
1 files changed, 16 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 } |