Exemplo n.º 1
0
func LoadEnv(loadDB bool) {
	godotenv.Load(Env)
	config.CheckEnv()

	if loadDB {
		db = config.NewDB()
	}
}
func TestMain(m *testing.M) {
	flag.Parse()
	os.RemoveAll("tmp")
	// Load test ENV variables
	godotenv.Load("../../.env.test")
	db = config.NewDB()
	models.New(db)
	if err := gofer.LoadAndPerform("db:empty", "--env=../../.env.test"); err != nil {
		panic(fmt.Sprintf("Unable to empty database %v", err))
	}

	if err := gofer.LoadAndPerform("db:migrate", "--env=../../.env.test"); err != nil {
		panic(fmt.Sprintf("Unable to migrate database %v", err))
	}
	os.Exit(m.Run())
}
Exemplo n.º 3
0
func SetupSpec() (db *gorm.DB) {
	godotenv.Load("../../.env.test")
	config.CheckEnv()
	db = config.NewDB()
	cmd.RegisterDb(db)

	cmd.RootCmd.SetArgs([]string{"db:empty", "--env=../../.env.test"})
	if err := cmd.RootCmd.Execute(); err != nil {
		panic(fmt.Sprintf("Unable to empty database %v", err))
	}

	cmd.RootCmd.SetArgs([]string{"db:migrate", "--env=../../.env.test"})
	if err := cmd.RootCmd.Execute(); err != nil {
		panic(fmt.Sprintf("Unable to migrate database %v", err))
	}

	models.New(db)
	return
}
// Up is executed when this migration is applied
func Up_20151127032902(txn *sql.Tx) {
	gdb := config.NewDB()
	models.New(gdb)
	defer gdb.Close()

	pts := models.PatternParts{
		models.PatternPart{Key: "lecturer", Value: `rav|norav`},
		models.PatternPart{Key: "lang", Value: `[[:lower:]]{3,4}`},
		models.PatternPart{Key: "name", Value: `[a-z\-\d]+`},
		models.PatternPart{Key: "content_type", Value: `[[:lower:]]+`},
		models.PatternPart{Key: "line", Value: `[a-z\-\d]+`},
		models.PatternPart{Key: "ot", Value: `o|t`},
		models.PatternPart{Key: "date", Value: `\d{4}-\d{2}-\d{2}`},
		models.PatternPart{Key: "cam", Value: `cam\d*_\d|xdcam\d*_\d{2,3}|cam\d*|xdcam\d*`},
		models.PatternPart{Key: "archive_type", Value: `kabbalah|arvut|ligdol`},
		models.PatternPart{Key: "index", Value: `n\d`},
	}

	for _, pt := range pts {
		if err := pt.Save(); err != nil {
			log.Panicln(stacktrace.Propagate(err, "Unable to save pattern", pt))
		}
	}
}