xorm: xorm.io/xorm/migrate Index | Files

package migrate

import "xorm.io/xorm/migrate"


Package Files



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")

type InitSchemaFunc Uses

type InitSchemaFunc func(*xorm.Engine) error

InitSchemaFunc is the func signature for initializing the schemas.

type Migrate Uses

type Migrate struct {
    // contains filtered or unexported fields

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

func New Uses

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

New returns a new Gormigrate.

func (*Migrate) InitSchema Uses

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 Uses

func (m *Migrate) Migrate() error

Migrate executes all migrations that did not run yet.

func (*Migrate) RollbackLast Uses

func (m *Migrate) RollbackLast() error

RollbackLast undo the last migration

func (*Migrate) RollbackMigration Uses

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

RollbackMigration undo a migration.

type MigrateFunc Uses

type MigrateFunc func(*xorm.Engine) error

MigrateFunc is the func signature for migrating.

type Migration Uses

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 Uses

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 Uses

type RollbackFunc func(*xorm.Engine) error

RollbackFunc is the func signature for rollbacking.

Package migrate imports 3 packages (graph). Updated 2021-01-21. Refresh now. Tools for package owners.