diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2026-11-13 22:13:14 -0800 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2026-11-13 22:13:14 -0800 |
| commit | 9656e14fc758053f34f5cb0e906093e2a18f6162 (patch) | |
| tree | 3d7799305de92be6a09bcd12c29fe0843b7b8cab /internal/configloader | |
| parent | Remove migration dependencies (diff) | |
| download | cli-9656e14fc758053f34f5cb0e906093e2a18f6162.zip | |
Remove timestamp version style in favor of always using sequential
Diffstat (limited to 'internal/configloader')
| -rw-r--r-- | internal/configloader/configloader.go | 34 | ||||
| -rw-r--r-- | internal/configloader/configloader_test.go | 21 |
2 files changed, 3 insertions, 52 deletions
diff --git a/internal/configloader/configloader.go b/internal/configloader/configloader.go index 81a9564..1d36ae8 100644 --- a/internal/configloader/configloader.go +++ b/internal/configloader/configloader.go @@ -10,31 +10,16 @@ package configloader import ( "errors" - "fmt" "os" "path/filepath" - "reflect" "runtime" "git.sr.ht/~eugenetriguba/envelope" "github.com/BurntSushi/toml" ) -type VersionStyle string - -const ( - VersionStyleSequential VersionStyle = "sequential" - VersionStyleTimestamp VersionStyle = "timestamp" -) - -var ( - ErrConfigFileNotFound = errors.New( - "bolt configuration file not found in current directory or any parent directories", - ) - ErrInvalidVersionStyle = fmt.Errorf( - "invalid version style for bolt migrations. supported styles: %v", - []VersionStyle{VersionStyleSequential, VersionStyleTimestamp}, - ) +var ErrConfigFileNotFound = errors.New( + "bolt configuration file not found in current directory or any parent directories", ) // Config represents the application configuration settings. @@ -50,8 +35,7 @@ type Config struct { } type MigrationsConfig struct { - DirectoryPath string `toml:"directory_path" env:"DIR_PATH"` - VersionStyle VersionStyle `toml:"version_style" env:"VERSION_STYLE"` + DirectoryPath string `toml:"directory_path" env:"DIR_PATH"` } type ConnectionConfig struct { @@ -60,12 +44,6 @@ type ConnectionConfig struct { MigrationsTable string `toml:"migrations_table" env:"MIGRATIONS_TABLE"` } -func init() { - envelope.RegisterTypeParser(reflect.TypeOf(VersionStyleSequential), envelope.TypeParserFunc(func(value string) (any, error) { - return VersionStyle(value), nil - })) -} - func NewConfig() (*Config, error) { filePath, err := findConfigFilePath() if err != nil && !errors.Is(err, ErrConfigFileNotFound) { @@ -75,7 +53,6 @@ func NewConfig() (*Config, error) { cfg := Config{ Migrations: MigrationsConfig{ DirectoryPath: "migrations", - VersionStyle: VersionStyleTimestamp, }, Connection: ConnectionConfig{ MigrationsTable: "bolt_migrations", @@ -93,11 +70,6 @@ func NewConfig() (*Config, error) { return nil, err } - if cfg.Migrations.VersionStyle != VersionStyleSequential && - cfg.Migrations.VersionStyle != VersionStyleTimestamp { - return nil, ErrInvalidVersionStyle - } - return &cfg, nil } diff --git a/internal/configloader/configloader_test.go b/internal/configloader/configloader_test.go index e634c15..4112580 100644 --- a/internal/configloader/configloader_test.go +++ b/internal/configloader/configloader_test.go @@ -18,34 +18,18 @@ func TestNewConfigDefaults(t *testing.T) { assert.Nil(t, err) check.Equal(t, cfg.Migrations.DirectoryPath, "migrations") - check.Equal(t, cfg.Migrations.VersionStyle, configloader.VersionStyleTimestamp) check.Equal(t, cfg.Connection.MigrationsTable, "bolt_migrations") } -func TestNewConfigWithInvalidVersionStyle(t *testing.T) { - fileCfg := configloader.Config{ - Migrations: configloader.MigrationsConfig{ - DirectoryPath: "myfancymigrations", - VersionStyle: "invalid", - }, - } - bolttest.CreateConfigFile(t, &fileCfg, "bolt.toml") - - _, err := configloader.NewConfig() - assert.ErrorIs(t, err, configloader.ErrInvalidVersionStyle) -} - func TestNewConfigFindsFileAndPopulatesConfigStruct(t *testing.T) { bolttest.UnsetEnv(t, "BOLT_DB_DSN") bolttest.UnsetEnv(t, "BOLT_DB_DRIVER") bolttest.UnsetEnv(t, "BOLT_DB_MIGRATIONS_TABLE") bolttest.UnsetEnv(t, "BOLT_MIGRATIONS_DIR_PATH") - bolttest.UnsetEnv(t, "BOLT_MIGRATIONS_VERSION_STYLE") expectedCfg := configloader.Config{ Migrations: configloader.MigrationsConfig{ DirectoryPath: "myfancymigrations", - VersionStyle: configloader.VersionStyleSequential, }, Connection: configloader.ConnectionConfig{ DSN: "postgresql://testuser:testpassword@testhost:1234/testdb", @@ -67,7 +51,6 @@ func TestNewConfigCanBeOverridenByEnvVars(t *testing.T) { fileCfg := configloader.Config{ Migrations: configloader.MigrationsConfig{ DirectoryPath: "cfgmigrations", - VersionStyle: configloader.VersionStyleSequential, }, Connection: configloader.ConnectionConfig{ DSN: "mysql://testuser:testpassword@testhost:1234/testdb", @@ -80,7 +63,6 @@ func TestNewConfigCanBeOverridenByEnvVars(t *testing.T) { envCfg := configloader.Config{ Migrations: configloader.MigrationsConfig{ DirectoryPath: "envmigrations", - VersionStyle: configloader.VersionStyleTimestamp, }, Connection: configloader.ConnectionConfig{ DSN: "postgresql://envtestuser:envtestpassword@envtesthost:4321/envtestdb", @@ -88,7 +70,6 @@ func TestNewConfigCanBeOverridenByEnvVars(t *testing.T) { MigrationsTable: "different_table", }, } - t.Setenv("BOLT_MIGRATIONS_VERSION_STYLE", string(envCfg.Migrations.VersionStyle)) t.Setenv("BOLT_MIGRATIONS_DIR_PATH", envCfg.Migrations.DirectoryPath) t.Setenv("BOLT_DB_DSN", envCfg.Connection.DSN) t.Setenv("BOLT_DB_DRIVER", envCfg.Connection.Driver) @@ -104,11 +85,9 @@ func TestNewConfigSearchesParentDirectories(t *testing.T) { bolttest.UnsetEnv(t, "BOLT_DB_DRIVER") bolttest.UnsetEnv(t, "BOLT_DB_MIGRATIONS_TABLE") bolttest.UnsetEnv(t, "BOLT_MIGRATIONS_DIR_PATH") - bolttest.UnsetEnv(t, "BOLT_MIGRATIONS_VERSION_STYLE") expectedCfg := configloader.Config{ Migrations: configloader.MigrationsConfig{ DirectoryPath: "differentmigrationsdir", - VersionStyle: configloader.VersionStyleSequential, }, Connection: configloader.ConnectionConfig{ MigrationsTable: "migration_table", |