Refactoring for Gin, NoSurf and SCS continues.
This commit is contained in:
31
internal/storage/seeds/thunderball_seed.go
Normal file
31
internal/storage/seeds/thunderball_seed.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"os"
|
||||
)
|
||||
|
||||
// this is an example currenlty not true data
|
||||
func Seed(db *sql.DB) error {
|
||||
if _, err := db.Exec(`
|
||||
INSERT INTO settings (k, v)
|
||||
SELECT 'site_name', 'SynLotto'
|
||||
WHERE NOT EXISTS (SELECT 1 FROM settings WHERE k='site_name');
|
||||
`); err != nil {
|
||||
// settings table is optional; remove if you don't use it
|
||||
}
|
||||
|
||||
// 2) admin user (idempotent + secret from env)
|
||||
adminUser := "admin"
|
||||
adminHash := os.Getenv("ADMIN_BCRYPT_HASH") // or build from ADMIN_PASSWORD
|
||||
if adminHash == "" {
|
||||
// skip silently if you don’t want to hard-require it
|
||||
return nil
|
||||
}
|
||||
_, err := db.Exec(`
|
||||
INSERT INTO users (username, password_hash, is_admin)
|
||||
VALUES (?, ?, 1)
|
||||
ON DUPLICATE KEY UPDATE is_admin=VALUES(is_admin)
|
||||
`, adminUser, adminHash)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user