Commit 29e0e0cc authored by Sonja Happ's avatar Sonja Happ
Browse files

make sure that at least one admin user is added to DB in release mode

parent d7de4213
......@@ -309,10 +309,18 @@ var WidgetE = Widget{
func DBAddAdminUser(db *gorm.DB) error {
db.AutoMigrate(&User{})
//create a copy of global test data
user0 := User0
// add admin user to DB
err := db.Create(&user0).Error
// Check if admin user exists in DB
var users []User
err := db.Where("Role = ?", "Admin").Find(&users).Error
if len(users) == 0 {
fmt.Println("No admin user found in DB, adding default admin user.")
//create a copy of global test data
user0 := User0
// add admin user to DB
err = db.Create(&user0).Error
}
return err
}
......
......@@ -133,6 +133,7 @@ func main() {
return
}
if mode == "test" {
// test mode: drop all tables and add test data to DB
database.DropTables(db)
log.Println("Database tables dropped, adding test data to DB")
err = database.DBAddTestData(db, basePath, r)
......@@ -142,6 +143,14 @@ func main() {
panic(err)
}
log.Println("Database initialized with test data")
} else {
// release mode: make sure that at least one admin user exists in DB
err = database.DBAddAdminUser(db)
if err != nil {
fmt.Println(err.Error())
fmt.Println("error: adding admin user failed, aborting")
panic(err)
}
}
amqpurl, _ := configuration.GolbalConfig.String("amqp.url")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment