diff options
author | zeripath <art27@cantab.net> | 2020-09-11 10:30:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-11 10:30:19 +0100 |
commit | e0ac545043d81c9096c161e127a9d4d9e88b1d9f (patch) | |
tree | 9b171681379415afe267a16f4c7059775eea0bab /models/models.go | |
parent | 25c870faa91954f86951c0e6f7ee25cff1a9869e (diff) | |
download | gitea-e0ac545043d81c9096c161e127a9d4d9e88b1d9f.tar.gz gitea-e0ac545043d81c9096c161e127a9d4d9e88b1d9f.zip |
Add postgres schema to the search_path on database connection (#12634)
Rather than rely on the user running the gitea server and db setting the
schema search_path correctly - if gitea is run with a schema we should
simply set the search_path to have that schema first in the path.
Fix #12505
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'models/models.go')
-rw-r--r-- | models/models.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/models/models.go b/models/models.go index 32df9bdfd8..6aaa26d627 100644 --- a/models/models.go +++ b/models/models.go @@ -155,6 +155,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 } |