Skip to content
Snippets Groups Projects
Commit e143f33d authored by Jonah Husson's avatar Jonah Husson
Browse files

Move conditions for database to variable

parent 7203302f
No related branches found
No related tags found
2 merge requests!38Project/haven beta,!36Update notifications bot to allow multiple identities & devices
......@@ -117,10 +117,10 @@ func newDatabase(username, password, dbName, address,
port string) (database, error) {
var err error
var db *gorm.DB
var useSqlite bool
var dialector gorm.Dialector
// Connect to the database if the correct information is provided
if address != "" && port != "" {
usePostgres := address != "" && port != ""
if usePostgres {
// Create the database connection
connectString := fmt.Sprintf(
postgresConnectString,
......@@ -131,7 +131,6 @@ func newDatabase(username, password, dbName, address,
}
dialector = postgres.Open(connectString)
} else {
useSqlite = true
jww.WARN.Printf("Database backend connection information not provided")
temporaryDbPath := fmt.Sprintf(sqliteDatabasePath, dbName)
dialector = sqlite.Open(temporaryDbPath)
......@@ -145,7 +144,7 @@ func newDatabase(username, password, dbName, address,
return nil, errors.Errorf("Unable to initialize in-memory sqlite database backend: %+v", err)
}
if useSqlite {
if !usePostgres {
// Enable foreign keys because they are disabled in SQLite by default
if err = db.Exec("PRAGMA foreign_keys = ON", nil).Error; err != nil {
return nil, err
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment