console

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package console is the artisan/ace-style command line: migration:run, migration:rollback --step=N, make:migration, db:seed and friends. Embed it in your app (App.Run) or use the `migro` launcher.

Index

Constants

View Source
const (
	ExitOK    = 0
	ExitError = 1
	ExitUsage = 2
)

Exit codes returned by Run.

Variables

This section is empty.

Functions

func ConnectionsFromEnv

func ConnectionsFromEnv() map[string]Connection

ConnectionsFromEnv builds the connection table from the environment:

MIGRO_DIALECT / MIGRO_DSN                  the default connection
MIGRO_<NAME>_DIALECT / MIGRO_<NAME>_DSN    a named one, used as --database=<name> (lower-cased)

func LoadDotEnv

func LoadDotEnv(path string) error

LoadDotEnv reads KEY=VALUE lines from path into the process environment. Variables that are already set win. A missing file is not an error.

Types

type App

type App struct {
	// Connections by name; Default names the one used without --database.
	Connections map[string]Connection
	Default     string

	// Env is the application environment ("production" triggers the safety prompt).
	// Defaults to MIGRO_ENV, then APP_ENV, then "development".
	Env string

	// Directories, relative to Root, used by make:* and migration:diff.
	Root          string
	MigrationsDir string // database/migrations
	SeedersDir    string // database/seeders
	FactoriesDir  string // database/factories
	ModelsDir     string // app/models
	ObserversDir  string // app/observers
	SchemaDir     string // database/schema: where schema:dump writes and migration:run looks for a dump

	// Models are the GORM models migration:diff compares with the database.
	Models []any

	// Migrations and Seeders default to everything registered via Register in init().
	Migrations func() ([]migrate.Migration, error)
	Seeders    func() []seed.Seeder

	Out, Err    io.Writer
	In          io.Reader
	Interactive bool // true when In is a terminal; enables the production confirmation prompt
	Now         func() time.Time
}

App wires commands to your project. Zero values get defaults in Run.

func FromEnv

func FromEnv(root string) (*App, error)

FromEnv builds an App for root from .env and the environment. Directories can be overridden with MIGRO_MIGRATIONS_DIR, MIGRO_SEEDERS_DIR, MIGRO_FACTORIES_DIR, MIGRO_MODELS_DIR, MIGRO_OBSERVERS_DIR and MIGRO_SCHEMA_DIR.

func (*App) Main

func (a *App) Main(args []string) int

Main runs a command with a background context. Convenient for a `main` function:

os.Exit(app.Main(os.Args[1:]))

func (*App) Run

func (a *App) Run(ctx context.Context, args []string) int

Run executes one command and returns a process exit code.

type Connection

type Connection func(ctx context.Context) (*migro.DB, error)

Connection opens a database on demand, so make:* commands never need one.

Jump to

Keyboard shortcuts

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