func redoRun(cmd *Command, args ...string) { confs, err := loadConfig() if err != nil { log.Fatal(err) } for _, conf := range confs { current, err := goose.GetDBVersion(conf) if err != nil { log.Fatal(err) } previous, err := goose.GetPreviousDBVersion(conf.MigrationsDir, current) if err != nil { log.Fatal(err) } if err := goose.RunMigrations(conf, conf.MigrationsDir, previous); err != nil { log.Fatal(err) } if err := goose.RunMigrations(conf, conf.MigrationsDir, current); err != nil { log.Fatal(err) } } }
// migrate runs all available migrations on a pgSQL database. func migrate(source string) error { log.Info("running database migrations") _, filename, _, _ := runtime.Caller(1) migrationDir := filepath.Join(filepath.Dir(filename), "/migrations/") conf := &goose.DBConf{ MigrationsDir: migrationDir, Driver: goose.DBDriver{ Name: "postgres", OpenStr: source, Import: "github.com/lib/pq", Dialect: &goose.PostgresDialect{}, }, } // Determine the most recent revision available from the migrations folder. target, err := goose.GetMostRecentDBVersion(conf.MigrationsDir) if err != nil { return fmt.Errorf("pgsql: could not get most recent migration: %v", err) } // Run migrations. err = goose.RunMigrations(conf, conf.MigrationsDir, target) if err != nil { return fmt.Errorf("pgsql: an error occured while running migrations: %v", err) } log.Info("database migration ran successfully") return nil }
func CreateOrUpdate() { conf, err := config() if err != nil { log.Panic(err) } dir := conf.MigrationsDir target, err := goose.GetMostRecentDBVersion(dir) if err != nil { log.Panic(err) } if err := goose.RunMigrations(conf, dir, target); err != nil { log.Panic(err) } }
func Up() { var dirpath string = viper.GetString("GOOSE_DIR") cfg := newGooseConf() fmt.Printf("Open str: %s", cfg.Driver.OpenStr) version, err := goose.GetMostRecentDBVersion(dirpath) if err != nil { log.Fatal(err) } err = goose.RunMigrations(cfg, dirpath, version) if err != nil { log.Fatal(err) } }
func redoRun(cmd *Command, args ...string) { conf, err := dbConfFromFlags() if err != nil { log.Fatal(err) } current, err := goose.GetDBVersion(conf) if err != nil { log.Fatal(err) } previous, err := goose.GetPreviousDBVersion(conf.MigrationsDir, current) if err != nil { log.Fatal(err) } if err := goose.RunMigrations(conf, conf.MigrationsDir, previous); err != nil { log.Fatal(err) } if err := goose.RunMigrations(conf, conf.MigrationsDir, current); err != nil { log.Fatal(err) } }
func upRun(cmd *Command, args ...string) { conf, err := dbConfFromFlags() if err != nil { log.Fatal(err) } target, err := goose.GetMostRecentDBVersion(conf.MigrationsDir) if err != nil { log.Fatal(err) } if err := goose.RunMigrations(conf, conf.MigrationsDir, target); err != nil { log.Fatal(err) } }
func Down() { var dirpath string = viper.GetString("GOOSE_DIR") cfg := newGooseConf() version, err := goose.GetMostRecentDBVersion(dirpath) if err != nil { log.Fatal(err) } previous, err := goose.GetPreviousDBVersion(dirpath, version) if err != nil { log.Fatal(err) } err = goose.RunMigrations(cfg, dirpath, previous) if err != nil { log.Fatal(err) } }
func upRun(cmd *Command, args ...string) { confs, err := loadConfig() if err != nil { log.Fatal(err) } for _, conf := range confs { target, err := goose.GetMostRecentDBVersion(conf.MigrationsDir) if err != nil { log.Fatal(err) } if err := goose.RunMigrations(conf, conf.MigrationsDir, target); err != nil { log.Fatal(err) } } }
func RunMigrations(version int64) error { goose_conf := generateGooseDbConf() return goose.RunMigrations(goose_conf, goose_conf.MigrationsDir, version) }