Documentation
¶
Index ¶
- func Down(ctx context.Context, db *bun.DB, migrationName string, queries []Query) error
- func DownWithOption(ctx context.Context, db *bun.DB, migrationName string, queries []Query, ...) error
- func RegisterCommands(migrations *migrate.Migrations, options Options) []contract.Command
- func RegisterContextCommands(contexts []ContextConfig, baseOptions Options) []contract.Command
- func RunQueries(ctx context.Context, db *bun.DB, direction string, migrationName string, ...) error
- func RunQueriesWithOption(ctx context.Context, db *bun.DB, direction string, migrationName string, ...) error
- func SetDefaultRunnerOption(option RunnerOption)
- func Up(ctx context.Context, db *bun.DB, migrationName string, queries []Query) error
- func UpWithOption(ctx context.Context, db *bun.DB, migrationName string, queries []Query, ...) error
- type ContextConfig
- type CreateCommand
- type InitCommand
- type MigrateCommand
- type Module
- type ModuleConfig
- type Options
- type Query
- type RollbackCommand
- type RunnerOption
- type StatusCommand
- type UnlockCommand
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DownWithOption ¶
func RegisterCommands ¶
func RegisterCommands( migrations *migrate.Migrations, options Options, ) []contract.Command
RegisterCommands builds the migration command family for one migration set. A nil set is refused rather than answered with no commands: the caller believes it registered the family and finds out at invocation time, as "unknown command", far from the wiring that caused it. The module gates its own optional set before calling here, so a binary that registers only migration contexts never reaches this refusal.
func RegisterContextCommands ¶ added in v1.2.0
func RegisterContextCommands( contexts []ContextConfig, baseOptions Options, ) []contract.Command
RegisterContextCommands builds one command family per migration context — db:<name>:migrate, db:<name>:rollback, ... — each pinned to its context's registry manager, so a binary with several databases registers the module once instead of once per context. Zero-value fields of baseOptions and of each context's Options resolve as documented on ContextConfig.
func RunQueries ¶
func RunQueriesWithOption ¶
func SetDefaultRunnerOption ¶ added in v1.3.0
func SetDefaultRunnerOption(option RunnerOption)
SetDefaultRunnerOption installs the process-wide fallback RunQueries uses when the context carries no option. It is the door of a host process that runs migrations on its own; the migrate commands do not leave anything behind in it — each installs its posture for the length of its run and puts back what was there, and a posture the host installs through this door while a command runs is left where the host put it.
func UpWithOption ¶
Types ¶
type ContextConfig ¶ added in v1.2.0
type ContextConfig struct {
Name string
Migrations *migrate.Migrations
Options Options
}
ContextConfig declares one migration context of a multi-database binary: its own migration set and its own command family (db:<name>:migrate, db:<name>:rollback, ...) pinned to one registry manager, so omitting the --manager flag can never migrate the wrong database. Zero-value ManagerRegistryServiceId, ManagerFlagName and CommandPrefix inherit from the base options handed to RegisterContextCommands, then from DefaultOptions(); the command prefix derives as <basePrefix>:<name>. ManagerName is intentionally per-context: a context targets the manager named after it (its own name) unless it pins its own Options.ManagerName, and it never inherits the base pin, because a migration context must target its own database.
type CreateCommand ¶
type CreateCommand struct {
// contains filtered or unexported fields
}
func NewCreateGoCommand ¶
func NewCreateGoCommand(migrations *migrate.Migrations, options Options) *CreateCommand
func (*CreateCommand) Description ¶
func (instance *CreateCommand) Description() string
func (*CreateCommand) Flags ¶
func (instance *CreateCommand) Flags() []clicontract.Flag
func (*CreateCommand) Name ¶
func (instance *CreateCommand) Name() string
func (*CreateCommand) Run ¶
func (instance *CreateCommand) Run(runtimeInstance runtimecontract.Runtime, commandContext *clicontract.CommandContext) (runErr error)
type InitCommand ¶
type InitCommand struct {
// contains filtered or unexported fields
}
func NewInitCommand ¶
func NewInitCommand(migrations *migrate.Migrations, options Options) *InitCommand
func (*InitCommand) Description ¶
func (instance *InitCommand) Description() string
func (*InitCommand) Flags ¶
func (instance *InitCommand) Flags() []clicontract.Flag
func (*InitCommand) Name ¶
func (instance *InitCommand) Name() string
func (*InitCommand) Run ¶
func (instance *InitCommand) Run(runtimeInstance runtimecontract.Runtime, commandContext *clicontract.CommandContext) (runErr error)
type MigrateCommand ¶
type MigrateCommand struct {
// contains filtered or unexported fields
}
func NewMigrateCommand ¶
func NewMigrateCommand(migrations *migrate.Migrations, options Options) *MigrateCommand
func (*MigrateCommand) Description ¶
func (instance *MigrateCommand) Description() string
func (*MigrateCommand) Flags ¶
func (instance *MigrateCommand) Flags() []clicontract.Flag
func (*MigrateCommand) Name ¶
func (instance *MigrateCommand) Name() string
func (*MigrateCommand) Run ¶
func (instance *MigrateCommand) Run(runtimeInstance runtimecontract.Runtime, commandContext *clicontract.CommandContext) (runErr error)
type Module ¶ added in v1.1.0
type Module struct {
// contains filtered or unexported fields
}
func NewModule ¶ added in v1.1.0
func NewModule(config ModuleConfig) *Module
func (*Module) Description ¶ added in v1.1.0
func (*Module) RegisterCliCommands ¶ added in v1.1.0
func (instance *Module) RegisterCliCommands(kernelInstance kernelcontract.Kernel) []clicontract.Command
type ModuleConfig ¶ added in v1.1.0
type ModuleConfig struct {
Migrations *migrate.Migrations
Options Options
/* Contexts declares additional per-database command families (db:<name>:migrate, ...) for multi-context binaries; it composes with the single-set form above, which keeps its unprefixed commands. */
Contexts []ContextConfig
}
type Options ¶
type Options struct {
ManagerRegistryServiceId string
ManagerFlagName string
CommandPrefix string
/* ManagerName pins the registry manager these commands use when the --manager flag is absent; empty falls back to the registry default. Pin one manager per command set so a multi-context binary can never migrate the wrong database by omitting the flag. */
ManagerName string
}
func DefaultOptions ¶
func DefaultOptions() Options
type RollbackCommand ¶
type RollbackCommand struct {
// contains filtered or unexported fields
}
func NewRollbackCommand ¶
func NewRollbackCommand(migrations *migrate.Migrations, options Options) *RollbackCommand
func (*RollbackCommand) Description ¶
func (instance *RollbackCommand) Description() string
func (*RollbackCommand) Flags ¶
func (instance *RollbackCommand) Flags() []clicontract.Flag
func (*RollbackCommand) Name ¶
func (instance *RollbackCommand) Name() string
func (*RollbackCommand) Run ¶
func (instance *RollbackCommand) Run(runtimeInstance runtimecontract.Runtime, commandContext *clicontract.CommandContext) (runErr error)
type RunnerOption ¶
func DefaultRunnerOption ¶
func DefaultRunnerOption() RunnerOption
type StatusCommand ¶
type StatusCommand struct {
// contains filtered or unexported fields
}
func NewStatusCommand ¶
func NewStatusCommand(migrations *migrate.Migrations, options Options) *StatusCommand
func (*StatusCommand) Description ¶
func (instance *StatusCommand) Description() string
func (*StatusCommand) Flags ¶
func (instance *StatusCommand) Flags() []clicontract.Flag
func (*StatusCommand) Name ¶
func (instance *StatusCommand) Name() string
func (*StatusCommand) Run ¶
func (instance *StatusCommand) Run(runtimeInstance runtimecontract.Runtime, commandContext *clicontract.CommandContext) (runErr error)
type UnlockCommand ¶
type UnlockCommand struct {
// contains filtered or unexported fields
}
func NewUnlockCommand ¶
func NewUnlockCommand(migrations *migrate.Migrations, options Options) *UnlockCommand
func (*UnlockCommand) Description ¶
func (instance *UnlockCommand) Description() string
func (*UnlockCommand) Flags ¶
func (instance *UnlockCommand) Flags() []clicontract.Flag
func (*UnlockCommand) Name ¶
func (instance *UnlockCommand) Name() string
func (*UnlockCommand) Run ¶
func (instance *UnlockCommand) Run(runtimeInstance runtimecontract.Runtime, commandContext *clicontract.CommandContext) (runErr error)