aboutsummaryrefslogtreecommitdiffstats
path: root/models/models.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-01-02 02:07:43 +0000
committerGitHub <noreply@github.com>2021-01-02 10:07:43 +0800
commitac88b0ee839bfbfae5759e211d0f9a69abe4d8f7 (patch)
tree9859ba50be23e00926eb973b77074ba5c1c7de7e /models/models.go
parentd44f192d3e584489de560485f871d3600f75a1cd (diff)
downloadgitea-ac88b0ee839bfbfae5759e211d0f9a69abe4d8f7.tar.gz
gitea-ac88b0ee839bfbfae5759e211d0f9a69abe4d8f7.zip
Ensure that schema search path is set with every connection on postgres (#14131)
* Ensure that schema search path is set with every connection on postgres Unfortunately every connection to postgres requires that the search path is set appropriately. This PR shadows the postgres driver to ensure that as soon as a connection is open, the search_path is set appropriately. Fix #14088 Signed-off-by: Andrew Thornton <art27@cantab.net> * no golangci-lint that is not a helpful suggestion Signed-off-by: Andrew Thornton <art27@cantab.net> * Use Execer if available Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'models/models.go')
-rw-r--r--models/models.go21
1 files changed, 10 insertions, 11 deletions
diff --git a/models/models.go b/models/models.go
index 6aaa26d627..f12a4e8b30 100644
--- a/models/models.go
+++ b/models/models.go
@@ -145,7 +145,16 @@ func getEngine() (*xorm.Engine, error) {
return nil, err
}
- engine, err := xorm.NewEngine(setting.Database.Type, connStr)
+ var engine *xorm.Engine
+
+ if setting.Database.UsePostgreSQL && len(setting.Database.Schema) > 0 {
+ // OK whilst we sort out our schema issues - create a schema aware postgres
+ registerPostgresSchemaDriver()
+ engine, err = xorm.NewEngine("postgresschema", connStr)
+ } else {
+ engine, err = xorm.NewEngine(setting.Database.Type, connStr)
+ }
+
if err != nil {
return nil, err
}
@@ -155,16 +164,6 @@ 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
}