Skip to content

Commit

Permalink
fix(config): normalize sqlite database path
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Jul 12, 2023
1 parent 777a77a commit f9b5ffa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ func parseConfig(path string) (*Config, error) {
},
DB: DBConfig{
Driver: "sqlite",
DataSource: filepath.Join(dataPath, "soft-serve.db"+
"?_pragma=busy_timeout(5000)&_pragma=foreign_keys(1)"),
DataSource: "soft-serve.db" +
"?_pragma=busy_timeout(5000)&_pragma=foreign_keys(1)",
},
}

Expand Down Expand Up @@ -335,6 +335,10 @@ func (c *Config) validate() error {
c.HTTP.TLSCertPath = filepath.Join(c.DataPath, c.HTTP.TLSCertPath)
}

if strings.HasPrefix(c.DB.Driver, "sqlite") && !filepath.IsAbs(c.DB.DataSource) {
c.DB.DataSource = filepath.Join(c.DataPath, c.DB.DataSource)
}

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion server/config/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ stats:
# The database configuration.
db:
# The database driver to use.
# Valid values are "sqlite3", "sqlite", "postgres", and "mysql".
# Valid values are "sqlite" and "postgres".
driver: "{{ .DB.Driver }}"
# The database data source name.
# This is driver specific and can be a file path or connection string.
Expand Down

0 comments on commit f9b5ffa

Please sign in to comment.