Documentation ¶
Index ¶
- Variables
- func Init() *xcmd.Command
- type DuplicatedIDError
- type Gormigrate
- func (g *Gormigrate) InitSchema(initSchema InitSchemaFunc)
- func (g *Gormigrate) Migrate() error
- func (g *Gormigrate) MigrateTo(migrationID string) error
- func (g *Gormigrate) RollbackLast() error
- func (g *Gormigrate) RollbackMigration(m *Migration) error
- func (g *Gormigrate) RollbackTo(migrationID string) error
- type InitSchemaFunc
- type Migrate
- type MigrateFunc
- type Migration
- type Options
- type ReservedIDError
- type RollbackFunc
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultOptions can be used if you don't want to think about options. DefaultOptions = &Options{ TableName: "migrations", IDColumnName: "id", IDColumnSize: 255, UseTransaction: false, ValidateUnknownMigrations: false, } // 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") // 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") )
Functions ¶
Types ¶
type DuplicatedIDError ¶
type DuplicatedIDError struct {
ID string
}
DuplicatedIDError is returned when more than one migration have the same ID
func (*DuplicatedIDError) Error ¶
func (e *DuplicatedIDError) Error() string
type Gormigrate ¶
type Gormigrate struct {
// contains filtered or unexported fields
}
Gormigrate represents a collection of all migrations of a database schema.
func (*Gormigrate) InitSchema ¶
func (g *Gormigrate) 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 (*Gormigrate) Migrate ¶
func (g *Gormigrate) Migrate() error
Migrate executes all migrations that did not run yet.
func (*Gormigrate) MigrateTo ¶
func (g *Gormigrate) MigrateTo(migrationID string) error
MigrateTo executes all migrations that did not run yet up to the migration that matches `migrationID`.
func (*Gormigrate) RollbackLast ¶
func (g *Gormigrate) RollbackLast() error
RollbackLast undo the last migration
func (*Gormigrate) RollbackMigration ¶
func (g *Gormigrate) RollbackMigration(m *Migration) error
RollbackMigration undo a migration.
func (*Gormigrate) RollbackTo ¶
func (g *Gormigrate) 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 ¶
InitSchemaFunc is the func signature for initializing the schema.
type Migrate ¶
type Migrate struct {
// contains filtered or unexported fields
}
Migrate represents a collection of all migrations of a database schema.
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) RollbackLast ¶
RollbackLast undo the last migration
func (*Migrate) RollbackMigration ¶
RollbackMigration undo a migration.
type MigrateFunc ¶
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 // IDColumnSize is the length of the migration id column IDColumnSize int // UseTransaction makes Gormigrate execute migrations inside a single transaction. // Keep in mind that not all databases support DDL commands inside transactions. UseTransaction bool // ValidateUnknownMigrations will cause migrate to fail if there's unknown migration // IDs in the database ValidateUnknownMigrations bool }
Options define options for all migrations.
type ReservedIDError ¶
type ReservedIDError struct {
ID string
}
ReservedIDError is returned when a migration is using a reserved ID
func (*ReservedIDError) Error ¶
func (e *ReservedIDError) Error() string
type RollbackFunc ¶
RollbackFunc is the func signature for rollbacking.