migrate

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2020 License: BSD-3-Clause Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultOptions can be used if you don't want to think about options.
	DefaultOptions = &Options{
		TableName:    "migrations",
		IDColumnName: "id",
	}

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

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

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

	// ErrNoRunnedMigration is returned when any runned migration was found while
	// running RollbackLast
	ErrNoRunnedMigration = errors.New("Could not find last runned migration")
)

Functions

This section is empty.

Types

type InitSchemaFunc

type InitSchemaFunc func(*xorm.Engine) error

InitSchemaFunc is the func signature for initializing the schemas.

type Migrate

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

Migrate represents a collection of all migrations of a database schemas.

func New

func New(db *xorm.Engine, options *Options, migrations []*Migration) *Migrate

New returns a new Gormigrate.

func (*Migrate) InitSchema

func (m *Migrate) 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 (*Migrate) Migrate

func (m *Migrate) Migrate() error

Migrate executes all migrations that did not run yet.

func (*Migrate) RollbackLast

func (m *Migrate) RollbackLast() error

RollbackLast undo the last migration

func (*Migrate) RollbackMigration

func (m *Migrate) RollbackMigration(mig *Migration) error

RollbackMigration undo a migration.

type MigrateFunc

type MigrateFunc func(*xorm.Engine) 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 Options

type Options struct {
	// TableName is the migration table.
	TableName string
	// IDColumnName is the name of column where the migration id will be stored.
	IDColumnName string
}

Options define options for all migrations.

type RollbackFunc

type RollbackFunc func(*xorm.Engine) 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