entmigrates

package
v0.2.16 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

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 {
	// 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 *gorm.DB) error

MigrateFunc is the func signature for migrating.

type Migration

type Migration struct {
	Name string

	Description string

	MigrationSql string

	// 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 *gorm.DB) error

RollbackFunc is the func signature for rollbacking.

Jump to

Keyboard shortcuts

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