Exemplo n.º 1
0
func LoadConfig() *Config {
	if config == nil {
		cfg := &Config{
			Env: *env,
		}

		cfg.DriverName = *driverName
		cfg.DataSourceName = *dataSourceName

		if *driverName == DefaultDriverName || *dataSourceName == DefaultDataSourceName {
			gDbConf, err := goose.NewDBConf("./db", *env, "")
			if err != nil {
				log.Fatal(err)
			}
			if *driverName == DefaultDriverName {
				cfg.DriverName = gDbConf.Driver.Name
			}
			if *dataSourceName == DefaultDataSourceName {
				cfg.DataSourceName = gDbConf.Driver.OpenStr
			}
		}

		config = cfg
	}

	return config
}
Exemplo n.º 2
0
func newGooseConf() *goose.DBConf {

	var p string = viper.GetString("GOOSE_DIR")
	var env string = strings.ToLower(viper.GetString("ENV"))
	var schema string = "db"
	g, err := goose.NewDBConf(p, env, schema)
	if err != nil {
		panic(err)
	}
	return g
}
Exemplo n.º 3
0
func getDBConfig(env string, configPath string) (*goose.DBConf, error) {
	//log.Printf("Goosing config for  %#v", env)
	//configPath := path.Join("../../../../deploy/db/")
	schema := "public"
	dbconf, err := goose.NewDBConf(configPath, env, schema)
	if err != nil {
		log.Printf("Problem with config %#v", err)
		return nil, err
	}
	//log.Printf("Conf %#v:", dbconf)
	return dbconf, nil
}
Exemplo n.º 4
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
}
Exemplo n.º 5
0
func initDb() *gorp.DbMap {
	conf, err := goose.NewDBConf(*flagPath, *flagEnv)

	if err != nil {
		log.Fatal(err)
		return nil
	}

	log.Printf("Connecting to %v, %v", conf.Driver.Name, conf.Driver.OpenStr)

	db, err := sql.Open(conf.Driver.Name, conf.Driver.OpenStr)

	dbmap := &gorp.DbMap{Db: db, Dialect: gorp.MySQLDialect{"InnoDB", "UTF8"}}

	dbmap.TraceOn("[gorp]", log.New(os.Stdout, "myapp:", log.Lmicroseconds))
	dbmap.AddTableWithName(models.User{}, "users").SetKeys(true, "Id")

	return dbmap
}
Exemplo n.º 6
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
}
Exemplo n.º 7
0
// helper to create a DBConf from the given flags
func dbConfFromFlags() (dbconf *goose.DBConf, err error) {
	return goose.NewDBConf(*flagPath, *flagEnv)
}
Exemplo n.º 8
0
func config() (*goose.DBConf, error) {
	return goose.NewDBConf("db", *env, "")
}