aboutsummaryrefslogtreecommitdiffstats
path: root/integrations/migration-test/migration_test.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-08-24 17:24:45 +0800
committerAntoine GIRARD <sapk@users.noreply.github.com>2019-08-24 11:24:45 +0200
commitf83db078f0603c775cd1b1bb016f996b65a04835 (patch)
tree9895f852c768d43b384ba36259b44d9506b04093 /integrations/migration-test/migration_test.go
parent26af3401c36e6316b81b92bf6a776bf2442d251c (diff)
downloadgitea-f83db078f0603c775cd1b1bb016f996b65a04835.tar.gz
gitea-f83db078f0603c775cd1b1bb016f996b65a04835.zip
Move database settings from models to setting (#7806)
* move database settings from models to setting * update docs * fix checkout pr * fix tests * fix lint * remove unsupported tidb options * correct wrong variable name * remove tidb totally
Diffstat (limited to 'integrations/migration-test/migration_test.go')
-rw-r--r--integrations/migration-test/migration_test.go48
1 files changed, 24 insertions, 24 deletions
diff --git a/integrations/migration-test/migration_test.go b/integrations/migration-test/migration_test.go
index 858f339b89..3b47f0d7fc 100644
--- a/integrations/migration-test/migration_test.go
+++ b/integrations/migration-test/migration_test.go
@@ -54,7 +54,7 @@ func initMigrationTest(t *testing.T) {
setting.NewContext()
setting.CheckLFSVersion()
- models.LoadConfigs()
+ setting.InitDBConfig()
setting.NewLogServices(true)
}
@@ -64,7 +64,7 @@ func availableVersions() ([]string, error) {
return nil, err
}
defer migrationsDir.Close()
- versionRE, err := regexp.Compile("gitea-v(?P<version>.+)\\." + regexp.QuoteMeta(models.DbCfg.Type) + "\\.sql.gz")
+ versionRE, err := regexp.Compile("gitea-v(?P<version>.+)\\." + regexp.QuoteMeta(setting.Database.Type) + "\\.sql.gz")
if err != nil {
return nil, err
}
@@ -85,7 +85,7 @@ func availableVersions() ([]string, error) {
}
func readSQLFromFile(version string) (string, error) {
- filename := fmt.Sprintf("integrations/migration-test/gitea-v%s.%s.sql.gz", version, models.DbCfg.Type)
+ filename := fmt.Sprintf("integrations/migration-test/gitea-v%s.%s.sql.gz", version, setting.Database.Type)
if _, err := os.Stat(filename); os.IsNotExist(err) {
return "", nil
@@ -114,17 +114,17 @@ func restoreOldDB(t *testing.T, version string) bool {
data, err := readSQLFromFile(version)
assert.NoError(t, err)
if len(data) == 0 {
- integrations.Printf("No db found to restore for %s version: %s\n", models.DbCfg.Type, version)
+ integrations.Printf("No db found to restore for %s version: %s\n", setting.Database.Type, version)
return false
}
switch {
- case setting.UseSQLite3:
- os.Remove(models.DbCfg.Path)
- err := os.MkdirAll(path.Dir(models.DbCfg.Path), os.ModePerm)
+ case setting.Database.UseSQLite3:
+ os.Remove(setting.Database.Path)
+ err := os.MkdirAll(path.Dir(setting.Database.Path), os.ModePerm)
assert.NoError(t, err)
- db, err := sql.Open("sqlite3", fmt.Sprintf("file:%s?cache=shared&mode=rwc&_busy_timeout=%d", models.DbCfg.Path, models.DbCfg.Timeout))
+ db, err := sql.Open("sqlite3", fmt.Sprintf("file:%s?cache=shared&mode=rwc&_busy_timeout=%d", setting.Database.Path, setting.Database.Timeout))
assert.NoError(t, err)
defer db.Close()
@@ -132,20 +132,20 @@ func restoreOldDB(t *testing.T, version string) bool {
assert.NoError(t, err)
db.Close()
- case setting.UseMySQL:
+ case setting.Database.UseMySQL:
db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s)/",
- models.DbCfg.User, models.DbCfg.Passwd, models.DbCfg.Host))
+ setting.Database.User, setting.Database.Passwd, setting.Database.Host))
assert.NoError(t, err)
defer db.Close()
- _, err = db.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS %s", models.DbCfg.Name))
+ _, err = db.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS %s", setting.Database.Name))
assert.NoError(t, err)
- _, err = db.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s", models.DbCfg.Name))
+ _, err = db.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s", setting.Database.Name))
assert.NoError(t, err)
db, err = sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?multiStatements=true",
- models.DbCfg.User, models.DbCfg.Passwd, models.DbCfg.Host, models.DbCfg.Name))
+ setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.Name))
assert.NoError(t, err)
defer db.Close()
@@ -153,21 +153,21 @@ func restoreOldDB(t *testing.T, version string) bool {
assert.NoError(t, err)
db.Close()
- case setting.UsePostgreSQL:
+ case setting.Database.UsePostgreSQL:
db, err := sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/?sslmode=%s",
- models.DbCfg.User, models.DbCfg.Passwd, models.DbCfg.Host, models.DbCfg.SSLMode))
+ setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.SSLMode))
assert.NoError(t, err)
defer db.Close()
- _, err = db.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS %s", models.DbCfg.Name))
+ _, err = db.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS %s", setting.Database.Name))
assert.NoError(t, err)
- _, err = db.Exec(fmt.Sprintf("CREATE DATABASE %s", models.DbCfg.Name))
+ _, err = db.Exec(fmt.Sprintf("CREATE DATABASE %s", setting.Database.Name))
assert.NoError(t, err)
db.Close()
db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=%s",
- models.DbCfg.User, models.DbCfg.Passwd, models.DbCfg.Host, models.DbCfg.Name, models.DbCfg.SSLMode))
+ setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.Name, setting.Database.SSLMode))
assert.NoError(t, err)
defer db.Close()
@@ -175,10 +175,10 @@ func restoreOldDB(t *testing.T, version string) bool {
assert.NoError(t, err)
db.Close()
- case setting.UseMSSQL:
- host, port := models.ParseMSSQLHostPort(models.DbCfg.Host)
+ case setting.Database.UseMSSQL:
+ host, port := setting.ParseMSSQLHostPort(setting.Database.Host)
db, err := sql.Open("mssql", fmt.Sprintf("server=%s; port=%s; database=%s; user id=%s; password=%s;",
- host, port, "master", models.DbCfg.User, models.DbCfg.Passwd))
+ host, port, "master", setting.Database.User, setting.Database.Passwd))
assert.NoError(t, err)
defer db.Close()
@@ -191,7 +191,7 @@ func restoreOldDB(t *testing.T, version string) bool {
dbname := statement[5 : len(statement)-1]
db.Close()
db, err = sql.Open("mssql", fmt.Sprintf("server=%s; port=%s; database=%s; user id=%s; password=%s;",
- host, port, dbname, models.DbCfg.User, models.DbCfg.Passwd))
+ host, port, dbname, setting.Database.User, setting.Database.Passwd))
assert.NoError(t, err)
defer db.Close()
}
@@ -210,7 +210,7 @@ func wrappedMigrate(x *xorm.Engine) error {
func doMigrationTest(t *testing.T, version string) {
integrations.PrintCurrentTest(t)
- integrations.Printf("Performing migration test for %s version: %s\n", models.DbCfg.Type, version)
+ integrations.Printf("Performing migration test for %s version: %s\n", setting.Database.Type, version)
if !restoreOldDB(t, version) {
return
}
@@ -227,7 +227,7 @@ func doMigrationTest(t *testing.T, version string) {
func TestMigrations(t *testing.T) {
initMigrationTest(t)
- dialect := models.DbCfg.Type
+ dialect := setting.Database.Type
versions, err := availableVersions()
assert.NoError(t, err)