Refactor and remove sqlite and replace with MySQL

This commit is contained in:
2025-10-23 18:43:31 +01:00
parent d53e27eea8
commit 21ebc9c34b
139 changed files with 1013 additions and 529 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
}