From 28d5cd7b287c75508f01af35a1fa361dfa67f6c4 Mon Sep 17 00:00:00 2001 From: John Doe Date: Sat, 26 Oct 2024 16:06:47 +0000 Subject: [PATCH] feat: allow setting schema for connection in postgres (#2777) This PR introduce a new config for database, `database.schema`, allowing user to specify a specific schema to use for their postgres database connection. As the default value is set, it will be backward compatible. Related discussion: https://community.vikunja.io/t/postgres-database-has-error-pq-relation-tasks-does-not-exist/1333 Reviewed-on: https://kolaente.dev/vikunja/vikunja/pulls/2777 Co-authored-by: John Doe Co-committed-by: John Doe --- pkg/config/config.go | 2 ++ pkg/db/db.go | 1 + 2 files changed, 3 insertions(+) diff --git a/pkg/config/config.go b/pkg/config/config.go index 9eef87189..f24deb069 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -93,6 +93,7 @@ const ( DatabaseSslKey Key = `database.sslkey` DatabaseSslRootCert Key = `database.sslrootcert` DatabaseTLS Key = `database.tls` + DatabaseSchema Key = `database.schema` TypesenseEnabled Key = `typesense.enabled` TypesenseURL Key = `typesense.url` @@ -344,6 +345,7 @@ func InitDefaultConfig() { DatabaseSslKey.setDefault("") DatabaseSslRootCert.setDefault("") DatabaseTLS.setDefault("false") + DatabaseSchema.setDefault("public") // Typesense TypesenseEnabled.setDefault(false) diff --git a/pkg/db/db.go b/pkg/db/db.go index 798fcc149..abce9846a 100644 --- a/pkg/db/db.go +++ b/pkg/db/db.go @@ -165,6 +165,7 @@ func initPostgresEngine() (engine *xorm.Engine, err error) { if err != nil { return } + engine.SetSchema(config.DatabaseSchema.GetString()) engine.SetMaxOpenConns(config.DatabaseMaxOpenConnections.GetInt()) engine.SetMaxIdleConns(config.DatabaseMaxIdleConnections.GetInt()) max, err := time.ParseDuration(strconv.Itoa(config.DatabaseMaxConnectionLifetime.GetInt()) + `ms`)