-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
database: check before adding default user
- Loading branch information
1 parent
a63acc4
commit 903f7f5
Showing
1 changed file
with
10 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,13 +58,22 @@ const DefaultNumDisplayRows = 25 | |
|
||
// AddDefaultUser adds the default user to the system, so the referential integrity of licence user_id 0 works | ||
func AddDefaultUser() error { | ||
// Make sure the default user doesn't exist already | ||
existsAlready, err := CheckUserExists("default") | ||
if err != nil { | ||
return err | ||
} | ||
if existsAlready { | ||
return nil | ||
} | ||
|
||
// Add the new user to the database | ||
dbQuery := ` | ||
INSERT INTO users (auth0_id, user_name, email, display_name) | ||
VALUES ($1, $2, $3, $4) | ||
ON CONFLICT (user_name) | ||
DO NOTHING` | ||
_, err := DB.Exec(context.Background(), dbQuery, "", "default", "[email protected]", | ||
_, err = DB.Exec(context.Background(), dbQuery, "", "default", "[email protected]", | ||
"Default system user") | ||
if err != nil { | ||
log.Printf("Error when adding the default user to the database: %v", err) | ||
|