Help us shape the future of Go! Take the 2026 Go Developer Survey

command

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package command provides migration and seeder commands for a consumer binary. Parse arguments before starting services; Run uses explicitly supplied resources and leaves their lifecycle with the caller's application. No command resets data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	// contains filtered or unexported fields
}

Command is an immutable, validated invocation. Its zero value is invalid.

func Parse

func Parse(args []string, help io.Writer) (Command, error)

Parse validates arguments without application construction or database I/O. Help returns flag.ErrHelp after writing usage to help. Repeated --id flags select seeders for seed run; omission selects the complete seeder registry. --database names the connection of commands that use one; --schema selects one migration target on it.

func (Command) Database

func (c Command) Database() database.ConnectionName

Database is the --database selection; empty selects the caller's default connection. Whoever assembles Resources opens that connection and names it in Resources.DatabaseName.

func (Command) NeedsDatabase

func (c Command) NeedsDatabase() bool

NeedsDatabase reports whether Run uses a database connection. Listing seeders or prunables and showing a migration read only their registries, so resource assembly can leave the pool unconnected.

func (Command) Run

func (c Command) Run(ctx context.Context, resources Resources, output io.Writer) error

Run executes the selected operation exactly once. Status reports history drift and returns its conflict error; it never applies migrations. Up and seed run write confirmed progress even on failure, then return the original outcome. An output error may follow committed work and never triggers an automatic retry.

type MigrationTarget

type MigrationTarget struct {
	Schema string
	Runner *migrate.Postgres
}

MigrationTarget is the runner of one schema's migration history.

type Resources

type Resources struct {
	Migrations       *migrate.Postgres
	MigrationTargets []MigrationTarget
	Seeders          *seed.Registry
	Prunables        *prune.Registry
	Database         *database.DB
	DatabaseName     database.ConnectionName
}

Resources binds already assembled application services. Only the resources required by the selected command are used. Commands never start or close them.

Migration commands use either one Migrations runner or MigrationTargets, the per-schema runners of one database; --schema selects among targets. Database and MigrationTargets belong to the connection named by DatabaseName, which a --database selection must match. Leave DatabaseName empty for resources that were not assembled for a named selection; such resources accept none.

Jump to

Keyboard shortcuts

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