diff --git a/integrations/integration_test.go b/integrations/integration_test.go index 36e0682099b9e..3942d54410571 100644 --- a/integrations/integration_test.go +++ b/integrations/integration_test.go @@ -198,16 +198,6 @@ func initIntegrationTest() { } } - // Make the user's default search path the created schema; this will affect new connections - if _, err = db.Exec(fmt.Sprintf(`ALTER USER "%s" SET search_path = %s`, setting.Database.User, setting.Database.Schema)); err != nil { - log.Fatalf("db.Exec: ALTER USER SET search_path: %v", err) - } - - // Make the current connection's search the created schema - if _, err = db.Exec(fmt.Sprintf(`SET search_path = %s`, setting.Database.Schema)); err != nil { - log.Fatalf("db.Exec: ALTER USER SET search_path: %v", err) - } - 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;", diff --git a/integrations/migration-test/migration_test.go b/integrations/migration-test/migration_test.go index 976a59a5791d8..7d77568aa57a7 100644 --- a/integrations/migration-test/migration_test.go +++ b/integrations/migration-test/migration_test.go @@ -194,11 +194,6 @@ func restoreOldDB(t *testing.T, version string) bool { 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() } diff --git a/models/models.go b/models/models.go index e0dd3ed2a4231..c0ea54bcc15c2 100644 --- a/models/models.go +++ b/models/models.go @@ -153,6 +153,16 @@ func getEngine() (*xorm.Engine, error) { engine.Dialect().SetParams(map[string]string{"DEFAULT_VARCHAR": "nvarchar"}) } engine.SetSchema(setting.Database.Schema) + if setting.Database.UsePostgreSQL && len(setting.Database.Schema) > 0 { + // Add the schema to the search path + if _, err := engine.Exec(`SELECT set_config( + 'search_path', + ? || ',' || current_setting('search_path'), + false)`, + setting.Database.Schema); err != nil { + return nil, err + } + } return engine, nil }