Skip to content

Commit

Permalink
database: check before adding default user
Browse files Browse the repository at this point in the history
  • Loading branch information
justinclift committed Jan 24, 2024
1 parent a63acc4 commit 903f7f5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion common/database/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 903f7f5

Please sign in to comment.