cli

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 18 Imported by: 0

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

View Source
const (
	DriverPostgres   = "postgres"
	DriverPostgreSQL = "postgresql"
	DriverMySQL      = "mysql"
	DriverSQLite     = "sqlite"
	DriverSQLite3    = "sqlite3"
	DriverClickHouse = "clickhouse"

	// SQL driver names
	SQLDriverPostgres   = "pgx"
	SQLDriverMySQL      = "mysql"
	SQLDriverSQLite     = "sqlite3"
	SQLDriverClickHouse = "clickhouse"
)

Driver name constants.

View Source
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:

  1. Command-line flags (highest)
  2. Environment variables
  3. 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"`
	Environments map[string]*Environment `yaml:",inline"`
}

ConfigFile represents the structure of .queen.yaml

type DBOpener

type DBOpener func(dsn string) (*sql.DB, error)

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 RegisterFunc

type RegisterFunc func(*queen.Queen)

RegisterFunc is a function that registers migrations with Queen. Users provide this function to register all their migrations.

Jump to

Keyboard shortcuts

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