Documentation ¶
Index ¶
- Variables
- type Config
- type DuplicatedIDError
- type Generation
- type GoMigrate
- func (g *GoMigrate) InitSchema(initSchema InitSchemaFunc)
- func (g *GoMigrate) Migrate() error
- func (g *GoMigrate) MigrateTo(migrationID string) error
- func (g *GoMigrate) RollbackLast() error
- func (g *GoMigrate) RollbackMigration(m *Migration) error
- func (g *GoMigrate) RollbackTo(migrationID string) error
- type InitSchemaFunc
- type Migrate
- type MigrateFunc
- type Migration
- type ReservedIDError
- type RollbackFunc
Constants ¶
This section is empty.
Variables ¶
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") )
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 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 (*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) MigrateTo ¶ added in v0.2.11
MigrateTo executes all migrations that did not run yet up to the migration that matches `migrationID`.
func (*GoMigrate) RollbackLast ¶ added in v0.2.11
RollbackLast undo the last migration
func (*GoMigrate) RollbackMigration ¶ added in v0.2.11
RollbackMigration undo a migration.
func (*GoMigrate) RollbackTo ¶ added in v0.2.11
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
InitSchemaFunc is the func signature for initializing the schema.
type MigrateFunc ¶ added in v0.2.11
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
RollbackFunc is the func signature for rollbacking.