Documentation
¶
Overview ¶
Package cli builds the Cobra command tree: migrate, migrate:rollback, migrate:fresh, migrate:status, db:seed, make:migration, make:seeder and make:factory.
Use it standalone (see cmd/dbkit) or mount it inside your own framework's CLI:
db := cli.NewRootCommand(cli.Options{})
db.Use = "db"
root.AddCommand(db) // myapp db migrate
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadDefaultEnv ¶
func LoadDefaultEnv()
LoadDefaultEnv loads the environment file the global dbkit launcher chose (DBKIT_ENV_FILE) or ".env" in the current directory. Project runners call it first thing in main.
func LoadDotEnv ¶
func LoadDotEnv(path string)
LoadDotEnv reads KEY=VALUE lines from path into the process environment. Variables that are already set are not overwritten. A missing file is not an error.
func MakeCommands ¶
MakeCommands returns only the generators (make:migration, make:seeder, make:factory). They need no database and no compiled project code, so the global dbkit launcher runs them itself.
func NewRootCommand ¶
NewRootCommand returns the root command with every subcommand attached.
Types ¶
type Options ¶
type Options struct {
// Driver and DSN are the defaults; flags --driver/--dsn and the DB_*
// environment variables (DB_DRIVER, DB_DSN, DB_HOST, ...) override them.
Driver string
DSN string
// Open creates the database handle. Default: driver.Open. Replace it to
// reuse your framework's connection.
Open func(driver, dsn string) (*sql.DB, error)
Migrations *migration.Registry // default: migration.Default
Seeders *seeder.Registry // default: seeder.Default
Migrator migration.Options // table name, lock
// Directories used by the make:* generators (relative to the working
// directory of the runner, i.e. the project root).
MigrationsDir string // default db/migrations
SeedersDir string // default db/seeders
FactoriesDir string // default db/factories
Out io.Writer // default os.Stdout
Err io.Writer // default os.Stderr
}
Options customise the command tree. Every field is optional.