Documentation
¶
Overview ¶
Package cli provides a command-line interface for Queen migrations.
The CLI allows users to manage database migrations through a simple command-line tool. Users create their own binary that imports their migrations and calls cli.Run().
Example usage:
// cmd/migrate/main.go
package main
import (
"github.com/honeynil/queen/cli"
"myapp/migrations"
)
func main() {
cli.Run(migrations.Register)
}
The CLI supports configuration through flags, environment variables, and an optional .queen.yaml config file.
Index ¶
Constants ¶
const ( DriverPostgres = "postgres" DriverPostgreSQL = "postgresql" DriverMySQL = "mysql" DriverSQLite = "sqlite" DriverSQLite3 = "sqlite3" DriverClickHouse = "clickhouse" // SQL driver names used with database/sql. // These are the actual driver names registered with sql.Register(). SQLDriverPostgres = "pgx" SQLDriverMySQL = "mysql" SQLDriverSQLite = "sqlite3" SQLDriverClickHouse = "clickhouse" )
Driver name constants.
These constants define the recognized driver names that can be used in configuration. Some drivers have multiple aliases for convenience.
const DefaultTableName = "queen_migrations"
Default table name for migrations.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
func Run(register RegisterFunc)
Run starts the CLI with the given migration registration function. This is the main entry point for users.
Configuration priority:
- Command-line flags (highest)
- Environment variables
- Config file .queen.yaml (lowest, requires --use-config)
func RunWithDB ¶
func RunWithDB(register RegisterFunc, dbOpener DBOpener)
RunWithDB starts the CLI with a custom database opener. If dbOpener is nil, uses sql.Open with the driver name.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App holds the CLI application state.
type Config ¶
type Config struct {
Driver string `yaml:"driver"`
DSN string `yaml:"dsn"`
Table string `yaml:"table"`
LockTimeout time.Duration `yaml:"lock_timeout"`
UseConfig bool `yaml:"-"`
Env string `yaml:"-"`
UnlockProduction bool `yaml:"-"`
Yes bool `yaml:"-"`
JSON bool `yaml:"-"`
Verbose bool `yaml:"-"`
// contains filtered or unexported fields
}
Config holds all configuration options for the CLI.
type ConfigFile ¶
type ConfigFile struct {
ConfigLocked bool `yaml:"config_locked"`
Naming *NamingConfig `yaml:"naming"`
Environments map[string]*Environment `yaml:",inline"`
}
ConfigFile represents the structure of .queen.yaml
type DBOpener ¶
DBOpener is a function that opens a database connection. It receives the DSN (data source name) and returns a *sql.DB.
type Environment ¶
type Environment struct {
Driver string `yaml:"driver"`
DSN string `yaml:"dsn"`
Table string `yaml:"table"`
LockTimeout time.Duration `yaml:"lock_timeout"`
RequireConfirmation bool `yaml:"require_confirmation"`
RequireExplicitUnlock bool `yaml:"require_explicit_unlock"`
}
Environment represents a single environment configuration.
type NamingConfig ¶ added in v0.2.0
type NamingConfig struct {
Pattern string `yaml:"pattern"` // sequential, sequential-padded, semver
Padding int `yaml:"padding"` // for sequential-padded
Enforce *bool `yaml:"enforce"` // pointer to distinguish between unset and false
}
NamingConfig represents naming pattern configuration in YAML.
type RegisterFunc ¶
RegisterFunc is a function that registers migrations with Queen. Users provide this function to register all their migrations.