コード例 #1
0
ファイル: cmd_status.go プロジェクト: l3msh0/goosees
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))
		}
	}
}
コード例 #2
0
ファイル: migrations.go プロジェクト: nota-ja/gobb
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
}
コード例 #3
0
ファイル: database_test.go プロジェクト: okoba/applikatoni
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
}
コード例 #4
0
ファイル: main.go プロジェクト: okoba/applikatoni
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
}