Example #1
0
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)
		}
	}
}
Example #2
0
// 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
}
Example #3
0
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)
	}
}
Example #4
0
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)
	}
}
Example #5
0
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)
	}
}
Example #6
0
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)
	}
}
Example #7
0
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)
	}
}
Example #8
0
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)
		}
	}
}
Example #9
0
func RunMigrations(version int64) error {
	goose_conf := generateGooseDbConf()
	return goose.RunMigrations(goose_conf, goose_conf.MigrationsDir, version)
}