diff options
| -rw-r--r-- | internal/configloader/configloader.go | 3 | ||||
| -rw-r--r-- | internal/configloader/configloader_unix_test.go | 2 | ||||
| -rw-r--r-- | internal/configloader/configloader_windows_test.go | 2 | ||||
| -rw-r--r-- | internal/repositories/migration_db_repo.go | 27 |
4 files changed, 24 insertions, 10 deletions
diff --git a/internal/configloader/configloader.go b/internal/configloader/configloader.go index 2c8893f..d85548a 100644 --- a/internal/configloader/configloader.go +++ b/internal/configloader/configloader.go @@ -97,6 +97,9 @@ func findConfigFilePath() (filePath string, err error) { } } +// fsRootDir retrieves the root directory +// of the filesystem on Windows or any unix-like +// operating system. func fsRootDir() string { if runtime.GOOS == "windows" { return os.Getenv("SystemDrive") diff --git a/internal/configloader/configloader_unix_test.go b/internal/configloader/configloader_unix_test.go index 25803d0..5c65c37 100644 --- a/internal/configloader/configloader_unix_test.go +++ b/internal/configloader/configloader_unix_test.go @@ -1,4 +1,4 @@ -//go:build unix +// go:build unix package configloader_test diff --git a/internal/configloader/configloader_windows_test.go b/internal/configloader/configloader_windows_test.go index 763a03e..cc044b1 100644 --- a/internal/configloader/configloader_windows_test.go +++ b/internal/configloader/configloader_windows_test.go @@ -1,4 +1,4 @@ -//go:build windows +// go:build windows package configloader_test diff --git a/internal/repositories/migration_db_repo.go b/internal/repositories/migration_db_repo.go index 378fa02..5571ab3 100644 --- a/internal/repositories/migration_db_repo.go +++ b/internal/repositories/migration_db_repo.go @@ -12,8 +12,10 @@ type MigrationDBRepo struct { db *sql.DB } -// NewMigrationDBRepo initializes the MigrationRepo with a -// database and ensures the bolt_migration table exists. +// NewMigrationDBRepo initializes the MigrationDBRepo with a +// database. Furthermore, it ensures the migration table it +// operates on exists. If it is unable to create or confirm +// the table exists, an error is returned. func NewMigrationDBRepo(db *sql.DB) (*MigrationDBRepo, error) { _, err := db.Exec(` CREATE TABLE IF NOT EXISTS bolt_migrations( @@ -27,6 +29,10 @@ func NewMigrationDBRepo(db *sql.DB) (*MigrationDBRepo, error) { return &MigrationDBRepo{db: db}, nil } +// List retrieves a map of migration models that can be +// looked up by their `Version`. All migrations retrieved +// will be ones that have been applied, and their message +// will always be an empty string. func (mr *MigrationDBRepo) List() (map[string]*models.Migration, error) { rows, err := mr.db.Query(`SELECT version FROM bolt_migrations;`) if err != nil { @@ -43,6 +49,9 @@ func (mr *MigrationDBRepo) List() (map[string]*models.Migration, error) { } migrations[version] = &models.Migration{ Version: strings.TrimSpace(version), + // Note: We don't store the user-friendly message for + // the migration in the database. It's purely for the + // user to understand what the migration was locally. Message: "", Applied: true, } @@ -53,10 +62,9 @@ func (mr *MigrationDBRepo) List() (map[string]*models.Migration, error) { // IsApplied checks if the given version has been applied. // -// Note that applied will be false when the version isn't -// applied and when the version might be applied, but there -// was an error. Check err first before looking at whether the -// version is applied. +// applied will be false when the version isn't applied and +// when the version might be applied, but there was an error. +// Check err first before looking at whether the version is applied. func (mr *MigrationDBRepo) IsApplied(version string) (applied bool, err error) { row := mr.db.QueryRow(`SELECT 1 FROM bolt_migrations WHERE version = $1`, version) err = row.Scan() @@ -70,7 +78,9 @@ func (mr *MigrationDBRepo) IsApplied(version string) (applied bool, err error) { } // Apply applies a migration by executing the corresponding upgrade script -// and added the applied migration version into the bolt_migrations table. +// and adding the applied migration version into the migrations table. When +// successfully applied, the `migration` model's `Applied` field will be set +// to true. func (mr *MigrationDBRepo) Apply(upgradeScript string, migration *models.Migration) error { tx, err := mr.db.Begin() if err != nil { @@ -100,7 +110,8 @@ func (mr *MigrationDBRepo) Apply(upgradeScript string, migration *models.Migrati } // Revert reverts a migration by executing the corresponding downgrade script -// and deleting the migration version into the bolt_migrations table. +// and deleting the migration version from the migrations table. When successfully +// reverted, the `migration` model's `Applied` field will be set to false. func (mr *MigrationDBRepo) Revert(downgradeScript string, migration *models.Migration) error { tx, err := mr.db.Begin() if err != nil { |