diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2024-01-13 18:23:48 -0500 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2024-01-13 18:23:48 -0500 |
| commit | 00aa327eb204d504f1e03dbe5a7cdec4af4ec913 (patch) | |
| tree | 571a5bc5ce52a11e0039f9763c89b9316e7bf9d4 /internal/commands/migrate.go | |
| parent | Tweak readme (diff) | |
| download | cli-00aa327eb204d504f1e03dbe5a7cdec4af4ec913.zip | |
Rework docs, add more output, and tweak tests
Diffstat (limited to '')
| -rw-r--r-- | internal/commands/up.go (renamed from internal/commands/migrate.go) | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/internal/commands/migrate.go b/internal/commands/up.go index 8c86291..c207a83 100644 --- a/internal/commands/migrate.go +++ b/internal/commands/up.go @@ -3,37 +3,42 @@ package commands import ( "context" "flag" - "fmt" - "os" "github.com/eugenetriguba/bolt/internal/configloader" + "github.com/eugenetriguba/bolt/internal/output" "github.com/eugenetriguba/bolt/internal/repositories" "github.com/eugenetriguba/bolt/internal/services" "github.com/eugenetriguba/bolt/internal/storage" "github.com/google/subcommands" ) -type UpgradeCmd struct{} +type UpCmd struct{} -func (*UpgradeCmd) Name() string { return "upgrade" } +func (*UpCmd) Name() string { + return "up" +} + +func (*UpCmd) Synopsis() string { + return "apply migrations against the database" +} -func (*UpgradeCmd) Synopsis() string { return "Upgrade the database to the latest migration." } -func (*UpgradeCmd) Usage() string { - return `upgrade: - Upgrade the database to the latest migration. +func (*UpCmd) Usage() string { + return `up: + Apply migrations against the database ` } -func (m *UpgradeCmd) SetFlags(f *flag.FlagSet) {} +func (m *UpCmd) SetFlags(f *flag.FlagSet) {} -func (m *UpgradeCmd) Execute( +func (m *UpCmd) Execute( _ context.Context, f *flag.FlagSet, _ ...interface{}, ) subcommands.ExitStatus { + consoleOutputter := output.ConsoleOutputter{} cfg, err := configloader.NewConfig() if err != nil { - fmt.Fprintln(os.Stderr, err) + consoleOutputter.Error(err.Error()) return subcommands.ExitFailure } @@ -42,27 +47,31 @@ func (m *UpgradeCmd) Execute( storage.DBConnectionString(&cfg.Connection), ) if err != nil { - fmt.Fprintln(os.Stderr, err) + consoleOutputter.Error(err.Error()) return subcommands.ExitFailure } defer db.Close() migrationDBRepo, err := repositories.NewMigrationDBRepo(db) if err != nil { - fmt.Fprintln(os.Stderr, err) + consoleOutputter.Error(err.Error()) return subcommands.ExitFailure } migrationFsRepo, err := repositories.NewMigrationFsRepo(cfg.MigrationsDir) if err != nil { - fmt.Fprintln(os.Stderr, err) + consoleOutputter.Error(err.Error()) return subcommands.ExitFailure } - migrationService := services.NewMigrationService(migrationDBRepo, migrationFsRepo) + migrationService := services.NewMigrationService( + migrationDBRepo, + migrationFsRepo, + consoleOutputter, + ) err = migrationService.ApplyAllMigrations() if err != nil { - fmt.Fprintln(os.Stderr, err) + consoleOutputter.Error(err.Error()) return subcommands.ExitFailure } |