commands

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterInitCommand

func RegisterInitCommand(register func(name, desc string, handler func(args []string, flags *flag.FlagSet) error, setupFlags func(fs *flag.FlagSet)), out io.Writer, errOut io.Writer)

RegisterInitCommand registers the "init" command. It scaffolds a new go-migration project with directories, a pre-wired cmd/migrator/main.go entry point, and a default config file. This command does not require a CommandContext or database connection.

func RegisterMakeFactoryCommand

func RegisterMakeFactoryCommand(register func(name, desc string, handler func(args []string, flags *flag.FlagSet) error, setupFlags func(fs *flag.FlagSet)), getCtx func() *CommandContext, out io.Writer)

RegisterMakeFactoryCommand registers the "make:factory" command. It generates a new factory file from a template with the correct struct scaffolding.

func RegisterMakeMigrationCommand

func RegisterMakeMigrationCommand(register func(name, desc string, handler func(args []string, flags *flag.FlagSet) error, setupFlags func(fs *flag.FlagSet)), getCtx func() *CommandContext, out io.Writer)

RegisterMakeMigrationCommand registers the "make:migration" command. It generates a new migration file from a template with the correct timestamp prefix and struct scaffolding. Supports --create and --table flags for pre-populated schema builder calls.

func RegisterMakeSeederCommand

func RegisterMakeSeederCommand(register func(name, desc string, handler func(args []string, flags *flag.FlagSet) error, setupFlags func(fs *flag.FlagSet)), getCtx func() *CommandContext, out io.Writer)

RegisterMakeSeederCommand registers the "make:seeder" command. It generates a new seeder file from a template with the correct struct scaffolding.

func RegisterMigrateCommand

func RegisterMigrateCommand(register func(name, desc string, handler func(args []string, flags *flag.FlagSet) error, setupFlags func(fs *flag.FlagSet)), getCtx func() *CommandContext, out io.Writer)

RegisterMigrateCommand registers the "migrate" command on the router.

func RegisterMigrateFreshCommand

func RegisterMigrateFreshCommand(register func(name, desc string, handler func(args []string, flags *flag.FlagSet) error, setupFlags func(fs *flag.FlagSet)), getCtx func() *CommandContext, out io.Writer, in io.Reader)

RegisterMigrateFreshCommand registers the "migrate:fresh" command that drops all tables and re-runs all migrations.

func RegisterMigrateInstallCommand

func RegisterMigrateInstallCommand(register func(name, desc string, handler func(args []string, flags *flag.FlagSet) error, setupFlags func(fs *flag.FlagSet)), getCtx func() *CommandContext)

RegisterMigrateInstallCommand registers the "migrate:install" command that creates the migration tracking table.

func RegisterMigrateRefreshCommand

func RegisterMigrateRefreshCommand(register func(name, desc string, handler func(args []string, flags *flag.FlagSet) error, setupFlags func(fs *flag.FlagSet)), getCtx func() *CommandContext, out io.Writer)

RegisterMigrateRefreshCommand registers the "migrate:refresh" command that resets all migrations and re-runs them.

func RegisterMigrateResetCommand

func RegisterMigrateResetCommand(register func(name, desc string, handler func(args []string, flags *flag.FlagSet) error, setupFlags func(fs *flag.FlagSet)), getCtx func() *CommandContext, out io.Writer, in io.Reader)

RegisterMigrateResetCommand registers the "migrate:reset" command that rolls back all migrations.

func RegisterMigrateRollbackCommand

func RegisterMigrateRollbackCommand(register func(name, desc string, handler func(args []string, flags *flag.FlagSet) error, setupFlags func(fs *flag.FlagSet)), getCtx func() *CommandContext, out io.Writer)

RegisterMigrateRollbackCommand registers the "migrate:rollback" command. It supports a --step flag to roll back a specific number of migrations. When --step is 0 (default), it rolls back the last batch.

func RegisterMigrateStatusCommand

func RegisterMigrateStatusCommand(register func(name, desc string, handler func(args []string, flags *flag.FlagSet) error, setupFlags func(fs *flag.FlagSet)), getCtx func() *CommandContext, out io.Writer)

RegisterMigrateStatusCommand registers the "migrate:status" command that displays the status of all registered migrations.

func RegisterSeedCommand

func RegisterSeedCommand(register func(name, desc string, handler func(args []string, flags *flag.FlagSet) error, setupFlags func(fs *flag.FlagSet)), getCtx func() *CommandContext)

RegisterSeedCommand registers the "db:seed" command that runs database seeders. It supports an optional --class flag to run a specific seeder by name. When --class is empty, all registered seeders are executed.

func RegisterSeedRollbackCommand

func RegisterSeedRollbackCommand(register func(name, desc string, handler func(args []string, flags *flag.FlagSet) error, setupFlags func(fs *flag.FlagSet)), getCtx func() *CommandContext)

RegisterSeedRollbackCommand registers the "db:seed:rollback" command that rolls back a specific seeder by name. The --class flag is required and specifies which seeder to roll back.

func RegisterSeedTruncateCommand

func RegisterSeedTruncateCommand(register func(name, desc string, handler func(args []string, flags *flag.FlagSet) error, setupFlags func(fs *flag.FlagSet)), getCtx func() *CommandContext)

RegisterSeedTruncateCommand registers the "db:seed:truncate" command that truncates (deletes all rows from) a specific seeder table. The --table flag is required and specifies which table to truncate.

Types

type CommandContext

type CommandContext struct {
	DB             *sql.DB
	Migrator       MigratorRunner
	Seeder         *seeder.Runner
	Generator      *generator.Generator
	TrackerEnsurer TrackerCreator
}

CommandContext holds the dependencies needed by CLI command handlers. It mirrors the fields of cli.CLIContext but lives in the commands package to avoid an import cycle between pkg/cli and pkg/cli/commands.

type MigrationStatusInfo

type MigrationStatusInfo struct {
	Name      string
	Applied   bool
	Batch     int
	AppliedAt *time.Time
}

MigrationStatusInfo holds the status of a single migration. It mirrors migrator.MigrationStatus without importing the package.

type MigratorRunner

type MigratorRunner interface {
	Up() error
	Rollback(steps int) error
	Reset() error
	Refresh() error
	Fresh() error
	Status() ([]MigrationStatusInfo, error)
}

MigratorRunner defines the migration operations needed by CLI commands. It is satisfied by *migrator.Migrator (via MigratorAdapter) but defined here as an interface to avoid an import cycle between commands and migrator.

type TrackerCreator

type TrackerCreator interface {
	EnsureTable() error
}

TrackerCreator creates a migration tracker for the given DB.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL