Skip to content

Commit

Permalink
fix: limit sqlite connection pool to one
Browse files Browse the repository at this point in the history
  • Loading branch information
muety committed Dec 14, 2021
1 parent c5db2c2 commit 28a3418
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ func (c *appConfig) GetWeeklyReportTime() string {
return strings.Split(c.ReportTimeWeekly, ",")[1]
}

func (c *dbConfig) IsSQLite() bool {
return c.Dialect == "sqlite3"
}

func (c *serverConfig) GetPublicUrl() string {
return strings.TrimSuffix(c.PublicUrl, "/")
}
Expand Down Expand Up @@ -365,6 +369,10 @@ func Load(version string) *Config {
if config.Db.MaxConn <= 0 {
logbuch.Fatal("you must allow at least one database connection")
}
if config.Db.MaxConn > 1 && config.Db.IsSQLite() {
logbuch.Warn("with sqlite, only a single connection is supported") // otherwise 'PRAGMA foreign_keys=ON' would somehow have to be set for every connection in the pool
config.Db.MaxConn = 1
}
if config.Mail.Provider != "" && findString(config.Mail.Provider, emailProviders, "") == "" {
logbuch.Fatal("unknown mail provider '%s'", config.Mail.Provider)
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func main() {
// Connect to database
var err error
db, err = gorm.Open(config.Db.GetDialector(), &gorm.Config{Logger: gormLogger})
if config.Db.Dialect == "sqlite3" {
if config.Db.IsSQLite() {
db.Exec("PRAGMA foreign_keys = ON;")
if !utils.IsCleanDB(db) && !utils.HasConstraints(db) {
db.DisableForeignKeyConstraintWhenMigrating = true
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.30.1
1.30.2

0 comments on commit 28a3418

Please sign in to comment.