Example #1
0
func statusRun(cmd *Command, args ...string) {

	confs, err := loadConfig()
	if err != nil {
		log.Fatal(err)
	}

	for _, conf := range confs {
		// collect all migrations
		min := int64(0)
		max := int64((1 << 63) - 1)
		migrations, e := goose.CollectMigrations(conf.MigrationsDir, min, max)
		if e != nil {
			log.Fatal(e)
		}

		db, e := goose.OpenDBFromDBConf(conf)
		if e != nil {
			log.Fatal("couldn't open DB:", e)
		}
		defer db.Close()

		// must ensure that the version table exists if we're running on a pristine DB
		if _, e := goose.EnsureDBVersion(conf, db); e != nil {
			log.Fatal(e)
		}

		fmt.Printf("goosees: status for environment '%v'\n", conf.Env)
		fmt.Println("    Applied At                  Migration")
		fmt.Println("    =======================================")
		for _, m := range migrations {
			printMigrationStatus(db, m.Version, filepath.Base(m.Source))
		}
	}
}
Example #2
0
func GetMigrationInfo() (latest_db_version int64, migrations []*goose.Migration, err error) {
	goose_conf := generateGooseDbConf()
	db := models.GetDbSession()

	latest_db_version, _ = goose.GetMostRecentDBVersion(goose_conf.MigrationsDir)
	current_db_version, _ := goose.EnsureDBVersion(goose_conf, db.Db)
	migrations, _ = goose.CollectMigrations(goose_conf.MigrationsDir, current_db_version, latest_db_version)

	return latest_db_version, migrations, err
}