Esempio 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))
		}
	}
}
Esempio n. 2
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
}