Files
website/internal/storage/seeds/thunderball_seed.go

32 lines
793 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 dont 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
}