csmigro

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2023 License: MIT Imports: 24 Imported by: 0

README

A database migration tool designed to make schema migrations easy.

Csmigro

LICENSE

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorLogger      = color.New(color.FgRed, color.Bold)
	ErrorLoggerLight = color.New(color.FgRed)
	InfoLogger       = color.New(color.FgCyan, color.Bold)
	InfoLoggerLight  = color.New(color.FgCyan)
	SuccessLogger    = color.New(color.FgGreen, color.Bold)
)

Functions

func SwapPlanDirection

func SwapPlanDirection(plan *models.Plan)

SwapPlanDirection alters the plan direction to the opposite direction.

Types

type Config

type Config struct {
	Logger  Logger
	LockKey string
	DryRun  bool
}

type EngineOption

type EngineOption func(*Morph) error

func SetDryRun

func SetDryRun(enable bool) EngineOption

SetDryRun will not execute any migrations if set to true, but will still log the migrations that would be executed.

func SetMigrationTableName

func SetMigrationTableName(name string) EngineOption

func SetStatementTimeoutInSeconds

func SetStatementTimeoutInSeconds(n int) EngineOption

func WithLock

func WithLock(key string) EngineOption

WithLock creates a lock table in the database so that the migrations are guaranteed to be executed from a single instance. The key is used for naming the mutex.

func WithLogger

func WithLogger(logger Logger) EngineOption

type Logger

type Logger interface {
	Printf(format string, v ...interface{})
	Println(v ...interface{})
}

type Morph

type Morph struct {
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, driver drivers.Driver, source sources.Source, options ...EngineOption) (*Morph, error)

New creates a new instance of the migrations engine from an existing db instance and a migrations source. If the driver implements the Lockable interface, it will also wait until it has acquired a lock. The context is propagated to the drivers lock method (if the driver implements divers.Locker interface) and it can be used to cancel the lock acquisition.

func (*Morph) Apply

func (m *Morph) Apply(limit int) (int, error)

Applies limited number of migrations upwards.

func (*Morph) ApplyAll

func (m *Morph) ApplyAll() error

ApplyAll applies all pending migrations.

func (*Morph) ApplyDown

func (m *Morph) ApplyDown(limit int) (int, error)

ApplyDown rollbacks a limited number of migrations if limit is given below zero, all down scripts are going to be applied.

func (*Morph) ApplyPlan

func (m *Morph) ApplyPlan(plan *models.Plan) error

func (*Morph) Close

func (m *Morph) Close() error

Close closes the underlying database connection of the engine.

func (*Morph) Diff

func (m *Morph) Diff(mode models.Direction) ([]*models.Migration, error)

Diff returns the difference between the applied migrations and the available migrations.

func (*Morph) GeneratePlan

func (m *Morph) GeneratePlan(migrations []*models.Migration, auto bool) (*models.Plan, error)

GeneratePlan returns the plan to apply these migrations and also includes the safe rollback steps for the given migrations.

func (*Morph) GetOppositeMigrations

func (m *Morph) GetOppositeMigrations(migrations []*models.Migration) ([]*models.Migration, error)

Directories

Path Synopsis
cmd
mysql
Initial code generated by generator.
Initial code generated by generator.

Jump to

Keyboard shortcuts

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