Skip to content
Snippets Groups Projects

Update notifications bot to allow multiple identities & devices

1 file
+ 3
4
Compare changes
  • Side-by-side
  • Inline
+ 3
4
@@ -117,10 +117,10 @@ func newDatabase(username, password, dbName, address,
@@ -117,10 +117,10 @@ func newDatabase(username, password, dbName, address,
port string) (database, error) {
port string) (database, error) {
var err error
var err error
var db *gorm.DB
var db *gorm.DB
var useSqlite bool
var dialector gorm.Dialector
var dialector gorm.Dialector
// Connect to the database if the correct information is provided
// Connect to the database if the correct information is provided
if address != "" && port != "" {
usePostgres := address != "" && port != ""
 
if usePostgres {
// Create the database connection
// Create the database connection
connectString := fmt.Sprintf(
connectString := fmt.Sprintf(
postgresConnectString,
postgresConnectString,
@@ -131,7 +131,6 @@ func newDatabase(username, password, dbName, address,
@@ -131,7 +131,6 @@ func newDatabase(username, password, dbName, address,
}
}
dialector = postgres.Open(connectString)
dialector = postgres.Open(connectString)
} else {
} else {
useSqlite = true
jww.WARN.Printf("Database backend connection information not provided")
jww.WARN.Printf("Database backend connection information not provided")
temporaryDbPath := fmt.Sprintf(sqliteDatabasePath, dbName)
temporaryDbPath := fmt.Sprintf(sqliteDatabasePath, dbName)
dialector = sqlite.Open(temporaryDbPath)
dialector = sqlite.Open(temporaryDbPath)
@@ -145,7 +144,7 @@ func newDatabase(username, password, dbName, address,
@@ -145,7 +144,7 @@ func newDatabase(username, password, dbName, address,
return nil, errors.Errorf("Unable to initialize in-memory sqlite database backend: %+v", err)
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
// Enable foreign keys because they are disabled in SQLite by default
if err = db.Exec("PRAGMA foreign_keys = ON", nil).Error; err != nil {
if err = db.Exec("PRAGMA foreign_keys = ON", nil).Error; err != nil {
return nil, err
return nil, err
Loading