Ejemplo n.º 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))
		}
	}
}
Ejemplo n.º 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
}
Ejemplo n.º 3
0
func newTestDb(t *testing.T) *sql.DB {
	testConf, err := goose.NewDBConf(dbConfigDirectory, "test", "")
	checkErr(t, err)

	db, err := goose.OpenDBFromDBConf(testConf)
	checkErr(t, err)

	currentVersion, err := goose.EnsureDBVersion(testConf, db)
	checkErr(t, err)

	newestVersion, err := goose.GetMostRecentDBVersion(migrationsDirectory)
	checkErr(t, err)

	if currentVersion != newestVersion {
		t.Errorf("test DB not fully migrated. current version: %d, possible version: %d", currentVersion, newestVersion)
	}

	return db
}
Ejemplo n.º 4
0
func isDBMigrated(db *sql.DB) (bool, error) {
	dbconf, err := goose.NewDBConf(*dbConfDir, *env, "")
	if err != nil {
		return false, err
	}

	currentVersion, err := goose.EnsureDBVersion(dbconf, db)
	if err != nil {
		return false, err
	}

	newestVersion, err := goose.GetMostRecentDBVersion(*migrationDir)
	if err != nil {
		return false, err
	}

	if currentVersion != newestVersion {
		return false, nil
	}

	return true, nil
}