diff options
author | guillep2k <18600385+guillep2k@users.noreply.github.com> | 2020-01-20 12:45:14 -0300 |
---|---|---|
committer | Antoine GIRARD <sapk@users.noreply.github.com> | 2020-01-20 16:45:14 +0100 |
commit | ad1b6d439fe0e0875e54227e0bc23a74411f490e (patch) | |
tree | 8e16e25a913d167ebb772ad2e0e92cbba9c56b66 /integrations/migration-test | |
parent | 6d6f1d568ec36786b1020f4b43cbd872228c6633 (diff) | |
download | gitea-ad1b6d439fe0e0875e54227e0bc23a74411f490e.tar.gz gitea-ad1b6d439fe0e0875e54227e0bc23a74411f490e.zip |
Add support for database schema in PostgreSQL (#8819)
* Add support for database schema
* Require setting search_path for the db user
* Add schema setting to admin/config.tmpl
* Use a schema different from default for psql tests
* Update postgres scripts to use custom schema
* Update to xorm/core 0.7.3 and xorm/xorm c37aff9b3a
* Fix migration test
Co-authored-by: Antoine GIRARD <sapk@users.noreply.github.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'integrations/migration-test')
-rw-r--r-- | integrations/migration-test/gitea-v1.5.3.postgres.sql.gz | bin | 16612 -> 16783 bytes | |||
-rw-r--r-- | integrations/migration-test/gitea-v1.6.4.postgres.sql.gz | bin | 17346 -> 17517 bytes | |||
-rw-r--r-- | integrations/migration-test/gitea-v1.7.0.postgres.sql.gz | bin | 17659 -> 17831 bytes | |||
-rw-r--r-- | integrations/migration-test/migration_test.go | 26 |
4 files changed, 26 insertions, 0 deletions
diff --git a/integrations/migration-test/gitea-v1.5.3.postgres.sql.gz b/integrations/migration-test/gitea-v1.5.3.postgres.sql.gz Binary files differindex 2fcad82111..2380f8dd7f 100644 --- a/integrations/migration-test/gitea-v1.5.3.postgres.sql.gz +++ b/integrations/migration-test/gitea-v1.5.3.postgres.sql.gz diff --git a/integrations/migration-test/gitea-v1.6.4.postgres.sql.gz b/integrations/migration-test/gitea-v1.6.4.postgres.sql.gz Binary files differindex 8db9022d1c..bd66f6ba4f 100644 --- a/integrations/migration-test/gitea-v1.6.4.postgres.sql.gz +++ b/integrations/migration-test/gitea-v1.6.4.postgres.sql.gz diff --git a/integrations/migration-test/gitea-v1.7.0.postgres.sql.gz b/integrations/migration-test/gitea-v1.7.0.postgres.sql.gz Binary files differindex ed66d41b89..e4716c6b43 100644 --- a/integrations/migration-test/gitea-v1.7.0.postgres.sql.gz +++ b/integrations/migration-test/gitea-v1.7.0.postgres.sql.gz diff --git a/integrations/migration-test/migration_test.go b/integrations/migration-test/migration_test.go index c274d482da..6cdfbf7d7d 100644 --- a/integrations/migration-test/migration_test.go +++ b/integrations/migration-test/migration_test.go @@ -168,6 +168,32 @@ func restoreOldDB(t *testing.T, version string) bool { assert.NoError(t, err) db.Close() + // Check if we need to setup a specific schema + if len(setting.Database.Schema) != 0 { + db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=%s", + setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.Name, setting.Database.SSLMode)) + if !assert.NoError(t, err) { + return false + } + schrows, err := db.Query(fmt.Sprintf("SELECT 1 FROM information_schema.schemata WHERE schema_name = '%s'", setting.Database.Schema)) + if !assert.NoError(t, err) || !assert.NotEmpty(t, schrows) { + return false + } + + if !schrows.Next() { + // Create and setup a DB schema + _, err = db.Exec(fmt.Sprintf("CREATE SCHEMA %s", setting.Database.Schema)) + assert.NoError(t, err) + } + schrows.Close() + + // Make the user's default search path the created schema; this will affect new connections + _, err = db.Exec(fmt.Sprintf(`ALTER USER "%s" SET search_path = %s`, setting.Database.User, setting.Database.Schema)) + assert.NoError(t, err) + + db.Close() + } + db, err = sql.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=%s", setting.Database.User, setting.Database.Passwd, setting.Database.Host, setting.Database.Name, setting.Database.SSLMode)) assert.NoError(t, err) |