Stack of changes to get gin, scs, nosurf running.
This commit is contained in:
35
internal/platform/database/schema.go
Normal file
35
internal/platform/database/schema.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package databasePlatform
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
databaseHelpers "synlotto-website/internal/helpers/database"
|
||||
migrationSQL "synlotto-website/internal/storage/migrations"
|
||||
)
|
||||
|
||||
func EnsureInitialSchema(db *sql.DB) error {
|
||||
fmt.Println("✅ EnsureInitialSchema called") // temp debug
|
||||
|
||||
var cnt int
|
||||
if err := db.QueryRow(migrationSQL.ProbeUsersTable).Scan(&cnt); err != nil {
|
||||
return fmt.Errorf("probe users table failed: %w", err)
|
||||
}
|
||||
fmt.Printf("👀 Probe users count = %d\n", cnt) // temp debug
|
||||
if cnt > 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// sanity: show embedded SQL length so we know it actually embedded
|
||||
fmt.Printf("📦 Initial SQL bytes: %d\n", len(migrationSQL.InitialSchema)) // temp debug
|
||||
|
||||
tx, err := db.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := databaseHelpers.ExecScript(tx, migrationSQL.InitialSchema); err != nil {
|
||||
_ = tx.Rollback()
|
||||
return fmt.Errorf("apply schema: %w", err)
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
Reference in New Issue
Block a user