Allow skip migrations in tests via environment variable (#32958)

This commit is contained in:
Dafydd 2021-04-15 10:32:49 +01:00 committed by GitHub
parent 501d5fbcc2
commit 01150ae962
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -447,6 +447,15 @@ func InitTestDB(t ITestDB, opts ...InitTestDBOpt) *SQLStore {
}
}
// useful if you already have a database that you want to use for tests.
// cannot just set it on testSQLStore as it overrides the config in Init
if _, present := os.LookupEnv("SKIP_MIGRATIONS"); present {
t.Log("Skipping database migrations")
if _, err := sec.NewKey("skip_migrations", "true"); err != nil {
t.Fatalf("Failed to create key: %s", err)
}
}
// need to get engine to clean db before we init
t.Logf("Creating database connection: %q", sec.Key("connection_string"))
engine, err := xorm.NewEngine(dbType, sec.Key("connection_string").String())