Refactoring for Gin, NoSurf and SCS continues.

This commit is contained in:
2025-10-24 13:08:53 +01:00
parent 7276903733
commit fb07c4a5eb
61 changed files with 546 additions and 524 deletions

View 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 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
}