command

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
const TimeLayout = "2006-01-02 15:04:05"

Variables

View Source
var (
	// Version represents the version of the application
	Version   = "0.1.0"
	BuildTime = "2025-11-05T09:00:00Z"
	GitCommit = "ab3cd4ef"
	GoVersion = "1.21"
)
View Source
var (
	// ShowVerbose flag
	ShowVerbose bool
	// ConfigFile path to the configuration file
	ConfigFile string
)
View Source
var OnConfigLoaded = func(cfg *config.Config) error {
	return nil
}

OnConfigLoaded hook. you can modify or validate the configuration here.

Functions

func Cfg added in v0.2.0

func Cfg() *config.Config

Cfg get config instance

func CreateCommand

func CreateCommand() *capp.Cmd

CreateCommand creates a new migration file

func DownCommand

func DownCommand() *capp.Cmd

DownCommand rolls back the last migration or a specific one

func HandleCreate

func HandleCreate(names []string) error

HandleCreate creates migration files

func HandleDown

func HandleDown(opt DownOption) error

HandleDown migration logic

func HandleExec

func HandleExec(opt ExecOption) error

HandleExec handles the exec command logic

func HandleInit

func HandleInit(opt InitOption) error

HandleInit handles the init command logic

func HandleShow

func HandleShow(opt ShowOption) error

HandleShow handles the show command logic

func HandleSkip

func HandleSkip(opt SkipOption) error

HandleSkip skips one or multi migration file(s)

func HandleStatus

func HandleStatus(_ StatusOption) error

HandleStatus display migration status

func HandleUp

func HandleUp(opt UpOption) error

HandleUp executes pending migrations

func InitCommand

func InitCommand() *capp.Cmd

InitCommand initializes the migration schema on db

func NewApp

func NewApp(name, version, description string) *capp.App

NewApp creates a new CLI application

func NewExecCommand

func NewExecCommand() *capp.Cmd

NewExecCommand executes SQL statement or SQL file directly

func NewShowCommand

func NewShowCommand() *capp.Cmd

NewShowCommand shows database information like tables or table schema

func NewUpCommand

func NewUpCommand() *capp.Cmd

NewUpCommand executes pending migrations

func SetBuildInfo added in v0.2.0

func SetBuildInfo(version, goVer, buildTime, gitCommit string)

SetBuildInfo initializes the version, build time, and git commit

func SetCfg added in v0.2.0

func SetCfg(c *config.Config)

SetCfg set config instance. use on manual run logic.

func SkipCommand

func SkipCommand() *capp.Cmd

SkipCommand skips one or multi migration file(s)

func StatusCommand

func StatusCommand() *capp.Cmd

StatusCommand shows the status of migrations

Types

type DB

type DB = database.DB

DB alias for database.DB

type DownOption

type DownOption struct {
	Number int
	// Yes 是否跳过确认
	Yes bool
}

DownOption represents the options for the down command

type ExecOption

type ExecOption struct {
	// SQL or sql-file to execute
	SQLOrFile string
	// Skip confirmation prompt
	Yes bool
}

ExecOption represents options for the exec command

type InitOption

type InitOption struct {
	Drop bool
}

type ShowOption

type ShowOption struct {
	// Show database tables
	Tables bool
	// Show one table schema
	Schema string
}

ShowOption represents options for the show command

type SkipOption

type SkipOption struct {
	FileNames []string
}

SkipOption skip migration file option

type StatusOption added in v0.2.0

type StatusOption struct {
}

StatusOption status command option

type UpOption

type UpOption struct {
	// 默认每执行一个都需要确认
	Yes bool
	// 跳过错误迁移并继续执行
	SkipErr bool
	// 只执行指定数量的迁移
	Number int
	// 查找迁移开始时间,默认只查找最近6个月的迁移文件
	StartTime string
}

UpOption represents options for the up command

Jump to

Keyboard shortcuts

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