func MigrateMaxMigrations(dbMap *gorp.DbMap, max int) (int, error) { source, dialect, err := migrationSource(dbMap) if err != nil { return 0, err } return migrate.ExecMax(dbMap.Db, dialect, source, migrate.Up, max) }
// Migrate performs schema migration. Migrations can occur in one of three // ways: // // - up: migrations are performed from the currently installed version upwards. // If count is 0, all unapplied migrations will be run. // // - down: migrations are performed from the current version downard. If count // is 0, all applied migrations will be run in a downard direction. // // - redo: migrations are first ran downard `count` times, and then are rand // upward back to the current version at the start of the process. If count is // 0, a count of 1 will be assumed. func Migrate(db *sql.DB, dir MigrateDir, count int) (int, error) { switch dir { case MigrateUp: return migrate.ExecMax(db, "postgres", Migrations, migrate.Up, count) case MigrateDown: return migrate.ExecMax(db, "postgres", Migrations, migrate.Down, count) case MigrateRedo: if count == 0 { count = 1 } down, err := migrate.ExecMax(db, "postgres", Migrations, migrate.Down, count) if err != nil { return down, err } return migrate.ExecMax(db, "postgres", Migrations, migrate.Up, down) default: return 0, errors.New("Invalid migration direction") } }
func MigrateMaxMigrations(dbMap *gorp.DbMap, max int) (int, error) { source := getSource() return migrate.ExecMax(dbMap.Db, migrationDialect, source, migrate.Up, max) }