-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Closed
Labels
🎯 featureCategorizes as related to a new featureCategorizes as related to a new feature
Description
Describe the feature
This issue was also mentioned in #3359 :
Currently, xorm doesn't support to customrize your schema on postgres database. So gogs too. You have to use public schema.
but now xorm already supports custom Schema, And after simple modification and testing, it is found that gogs can be installed and used normally.
Describe the solution you'd like
The main changes are as follows:
Index: internal/db/models.go
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/internal/db/models.go b/internal/db/models.go
--- a/internal/db/models.go (revision 37383d9a1fb90d91adfaf0d6adc33f17830c3e5b)
+++ b/internal/db/models.go (date 1640348764665)
@@ -134,6 +134,10 @@
return nil, fmt.Errorf("connect to database: %v", err)
}
+ if conf.Database.Type == "postgres" {
+ x.SetSchema(conf.Database.Schema)
+ }
+
x.SetMapper(core.GonicMapper{})
var logPath string
Index: internal/db/db.go
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/internal/db/db.go b/internal/db/db.go
--- a/internal/db/db.go (revision 37383d9a1fb90d91adfaf0d6adc33f17830c3e5b)
+++ b/internal/db/db.go (date 1640348761452)
@@ -78,8 +78,8 @@
dsn = fmt.Sprintf("postgres://%s:%s@:%s/%s%ssslmode=%s&host=%s",
url.QueryEscape(opts.User), url.QueryEscape(opts.Password), port, opts.Name, concate, opts.SSLMode, host)
} else {
- dsn = fmt.Sprintf("postgres://%s:%s@%s:%s/%s%ssslmode=%s",
- url.QueryEscape(opts.User), url.QueryEscape(opts.Password), host, port, opts.Name, concate, opts.SSLMode)
+ dsn = fmt.Sprintf("user='%s' password='%s' host='%s' port='%s' dbname='%s' sslmode='%s' search_path='%s'",
+ opts.User, opts.Password, host, port, opts.Name, opts.SSLMode, opts.Schema)
}
case "mssql":
Describe alternatives you've considered
none
Additional context
No response
Code of Conduct
- I agree to follow this project's Code of Conduct
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
🎯 featureCategorizes as related to a new featureCategorizes as related to a new feature