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,53 @@
package storage
import (
"database/sql"
"log"
"synlotto-website/config"
"synlotto-website/logging"
_ "modernc.org/sqlite"
)
var db *sql.DB
func InitDB(filepath string) *sql.DB {
var err error
cfg := config.Get()
db, err = sql.Open("sqlite", filepath)
if err != nil {
log.Fatal("❌ Failed to open DB:", err)
}
schemas := []string{
SchemaUsers,
SchemaThunderballResults,
SchemaThunderballPrizes,
SchemaLottoResults,
SchemaMyTickets,
SchemaUsersMessages,
SchemaUsersNotifications,
SchemaAuditLog,
SchemaAuditLogin,
SchemaLogTicketMatching,
SchemaAdminAccessLog,
SchemaNewAuditLog,
SchemaSyndicates,
SchemaSyndicateMembers,
SchemaSyndicateInvites,
SchemaSyndicateInviteTokens,
}
if cfg == nil {
logging.Error("❌ config is nil — did config.Init() run before InitDB?")
panic("config not ready")
}
for _, stmt := range schemas {
if _, err := db.Exec(stmt); err != nil {
log.Fatalf("❌ Failed to apply schema: %v", err)
}
}
return db
}