migrates

package
v0.2.10-44 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: Apache-2.0 Imports: 6 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("gormigrate: It's impossible to rollback this migration")

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

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

	// ErrNoRunMigration is returned when any run migration was found while
	// running RollbackLast
	ErrNoRunMigration = errors.New("gormigrate: 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("gormigrate: 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("gormigrate: Found migration in DB that does not exist in code")
)
View Source
var DefaultConfig = Config{
	TableName:                 "migrations",
	IDColumnName:              "id",
	IDColumnSize:              255,
	UseTransaction:            false,
	ValidateUnknownMigrations: false,
}

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

Functions

This section is empty.

Types

type Config added in v0.2.11

type Config struct {
	// TableName is the migration table.
	TableName string `yaml:"table_name"`

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

	// IDColumnSize is the length of the migration id column
	IDColumnSize int `yaml:"id_column_size"`

	// UseTransaction makes GoMigrate execute migrations inside a single transaction.
	// Keep in mind that not all databases support DDL commands inside transactions.
	UseTransaction bool `yaml:"use_transaction"`

	// ValidateUnknownMigrations will cause migrate to fail if there's unknown migration
	// IDs in the database
	ValidateUnknownMigrations bool `yaml:"validate_unknown_migrations"`
}

Config define options for all migrations.

type DuplicatedIDError added in v0.2.11

type DuplicatedIDError struct {
	ID string
}

DuplicatedIDError is returned when more than one migration have the same ID

func (*DuplicatedIDError) Error added in v0.2.11

func (e *DuplicatedIDError) Error() string

type Generation added in v0.2.11

type Generation func(g *gen.Generator) []interface{}

type GoMigrate added in v0.2.11

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

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

func New added in v0.2.11

func New(db *gorm.DB, config *Config, migrations []*Migration) *GoMigrate

New returns a new GoMigrate.

func (*GoMigrate) InitSchema added in v0.2.11

func (g *GoMigrate) InitSchema(initSchema InitSchemaFunc)

InitSchema sets a function that is run if no migration is found. The idea is preventing to run all migrations when a new clean database is being migrating. In this function you should create all tables and foreign key necessary to your application.

func (*GoMigrate) Migrate added in v0.2.11

func (g *GoMigrate) Migrate() error

Migrate executes all migrations that did not run yet.

func (*GoMigrate) MigrateTo added in v0.2.11

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

MigrateTo executes all migrations that did not run yet up to the migration that matches `migrationID`.

func (*GoMigrate) RollbackLast added in v0.2.11

func (g *GoMigrate) RollbackLast() error

RollbackLast undo the last migration

func (*GoMigrate) RollbackMigration added in v0.2.11

func (g *GoMigrate) RollbackMigration(m *Migration) error

RollbackMigration undo a migration.

func (*GoMigrate) RollbackTo added in v0.2.11

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

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

type InitSchemaFunc added in v0.2.11

type InitSchemaFunc func(*gorm.DB) error

InitSchemaFunc is the func signature for initializing the schema.

type Migrate added in v0.2.7

type Migrate func() *Migration

type MigrateFunc added in v0.2.11

type MigrateFunc func(*gorm.DB) error

MigrateFunc is the func signature for migrating.

type Migration

type Migration struct {
	// ID is the migration identifier. Usually a timestamp like "201601021504".
	ID string
	// Migrate is a function that will br executed while running this migration.
	Migrate MigrateFunc
	// Rollback will be executed on rollback. Can be nil.
	Rollback RollbackFunc
}

Migration represents a database migration (a modification to be made on the database).

type ReservedIDError added in v0.2.11

type ReservedIDError struct {
	ID string
}

ReservedIDError is returned when a migration is using a reserved ID

func (*ReservedIDError) Error added in v0.2.11

func (e *ReservedIDError) Error() string

type RollbackFunc added in v0.2.11

type RollbackFunc func(*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