Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
notifications-bot
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
archives
notifications-bot
Commits
e143f33d
Commit
e143f33d
authored
2 years ago
by
Jonah Husson
Browse files
Options
Downloads
Patches
Plain Diff
Move conditions for database to variable
parent
7203302f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!38
Project/haven beta
,
!36
Update notifications bot to allow multiple identities & devices
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
storage/database.go
+3
-4
3 additions, 4 deletions
storage/database.go
with
3 additions
and
4 deletions
storage/database.go
+
3
−
4
View file @
e143f33d
...
...
@@ -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
use
Sqlite
{
if
!
use
Postgres
{
// 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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment