Files
job-search/internal/cli/migrate/migrate.go
T
bwilliams 043e307663 Logging: structured slog messages throughout, and WithLogger options so callers choose the logger
Log messages are lower-case event names with their details as key/value
attributes ("error" for errors), in place of formatted strings.

Loggable package take a WithLogger option as part of their "New*" call,
defaulting to slog.Default(). Each tags its lines with its `component`.

Some debug loggers print directly rather than using slog when in
terminal logging mode.
2026-10-15 16:10:52 +01:00

44 lines
1.4 KiB
Go

// Package migrate provides the "migrate" command and its subcommands, which
// apply, roll back and report the store's migrations (goose, embedded in the
// store package) on the configured SQLite database.
//
// goose runs each migration in its own transaction, so a failed migration is
// rolled back and leaves the database at the previous version.
package migrate
import (
"log/slog"
"github.com/spf13/cobra"
"git.avsdev.uk/Go/job-search/internal/cli"
)
// NewCommand returns the "migrate" command, which migrates the database schema (see
// internal/store).
func NewCommand(opts *cli.Options) *cobra.Command {
cmd := &cobra.Command{
Use: "migrate",
Short: "Migrate SQLite database to latest version",
Long: `Migrate the SQLite database to the latest version.
Running without a subcommand is the same as running "migrate up": every pending
migration is applied.`,
Args: cobra.NoArgs,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
slog.Debug("command persistent pre-run", "command", "migrate")
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
slog.Debug("command persistent post-run", "command", "migrate")
},
RunE: func(cmd *cobra.Command, args []string) error {
slog.Debug("command run", "command", "migrate")
return runStepUp(cmd, opts, 0, false)
},
}
cmd.AddCommand(commandUp(opts))
cmd.AddCommand(commandDown(opts))
cmd.AddCommand(commandStatus(opts))
return cmd
}