migrates

package
v0.2.10-121 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRollbackImpossible is returned when trying to rollback a migration
	// that has no rollback function.
	ErrRollbackImpossible = errors.New("ormigrate: It's impossible to rollback this migration")

	// ErrNoMigrationDefined is returned when no migration is defined.
	ErrNoMigrationDefined = errors.New("ormigrate: No migration defined")

	// ErrMissingID is returned when the ID od migration is equal to ""
	ErrMissingID = errors.New("ormigrate: Missing ID in migration")

	// ErrNoRunMigration is returned when any run migration was found while
	// running RollbackLast
	ErrNoRunMigration = errors.New("ormigrate: Could not find last run migration")

	// ErrMigrationIDDoesNotExist is returned when migrating or rolling back to a migration ID that
	// does not exist in the list of migrations
	ErrMigrationIDDoesNotExist = errors.New("ormigrate: Tried to migrate to an ID that doesn't exist")

	// ErrUnknownPastMigration is returned if a migration exists in the DB that doesn't exist in the code
	ErrUnknownPastMigration = errors.New("ormigrate: Found migration in DB that does not exist in code")
)
View Source
var DefaultConfig = Config{
	TableName:     "migrations",
	ColumnName:    "id",
	ColumnSize:    255,
	MigrationPath: "./internal/schema/migrations",
}

DefaultConfig can be used if you don't want to think about config.

Functions

This section is empty.

Types

type Config

type Config struct {
	GetTx func(parent context.Context) Tx `yaml:"-"`

	// TableName is the migration table.
	TableName string `yaml:"table_name"`

	// ColumnName is the name of column where the migration id will be stored.
	ColumnName string `yaml:"column_name"`

	// ColumnSize is the length of the migration id column
	ColumnSize int `yaml:"column_size"`

	MigrationPath string `yaml:"sql_path"`
}

Config define config for all migrations.

type GoMigrate

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

GoMigrate represents a collection of all migrations of a database schema.

func New

func New(db *entsql.Driver, cfg *Config, migrations []*Migration, tables []*schema.Table) *GoMigrate

New returns a new GoMigrate.

func (*GoMigrate) Close

func (g *GoMigrate) Close() error

func (*GoMigrate) Cmd

func (g *GoMigrate) Cmd() *cli.Command

func (*GoMigrate) Create

func (g *GoMigrate) Create(tables []*schema.Table) error

func (*GoMigrate) List

func (g *GoMigrate) List() ([]*MigrationWrap, error)

func (*GoMigrate) Migrate

func (g *GoMigrate) Migrate() error

Migrate executes all migrations that did not run yet.

func (*GoMigrate) MigrateTo

func (g *GoMigrate) MigrateTo(name string) error

func (*GoMigrate) RollbackLast

func (g *GoMigrate) RollbackLast() error

RollbackLast undo the last migration

func (*GoMigrate) RollbackTo

func (g *GoMigrate) RollbackTo(name string) error

RollbackTo undoes migrations up to the given migration that matches the `migrationID`. Migration with the matching `name` is not rolled back.

type MigrateFunc

type MigrateFunc func(ctx context.Context, tx Tx) error

MigrateFunc is the func signature for migrating.

type Migration

type Migration struct {
	Name string

	Description string

	SchemaSqlFile string

	SkipExecSchemaSql bool

	// DataMigrate is a function that will br executed while running this migration.
	DataMigrate MigrateFunc

	// DataRollback will be executed on rollback. Can be nil.
	DataRollback RollbackFunc
}

Migration represents a database migration

type MigrationWrap

type MigrationWrap struct {
	*Migration
	Executed bool
}

type RollbackFunc

type RollbackFunc func(ctx context.Context, tx Tx) error

RollbackFunc is the func signature for rollbacking.

type Tx

type Tx interface {
	driver.Tx
	entsql.ExecQuerier
}

Jump to

Keyboard shortcuts

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