05/23 Phase 22
This commit is contained in:
+25
-9
@@ -50,7 +50,8 @@ def init_db():
|
||||
main_max INTEGER NOT NULL,
|
||||
bonus_count INTEGER NOT NULL DEFAULT 0,
|
||||
bonus_max INTEGER NOT NULL DEFAULT 0,
|
||||
active INTEGER NOT NULL DEFAULT 1
|
||||
active INTEGER NOT NULL DEFAULT 1,
|
||||
top_prize TEXT NOT NULL DEFAULT ''
|
||||
)
|
||||
""")
|
||||
|
||||
@@ -105,6 +106,15 @@ def init_db():
|
||||
)
|
||||
""")
|
||||
|
||||
# Migration: add top_prize column to existing databases
|
||||
cursor.execute("PRAGMA table_info(games)")
|
||||
cols = {r["name"] for r in cursor.fetchall()}
|
||||
if "top_prize" not in cols:
|
||||
cursor.execute(
|
||||
"ALTER TABLE games ADD COLUMN top_prize TEXT NOT NULL DEFAULT ''"
|
||||
)
|
||||
logger.info("[DB] Migrated: added top_prize column to games")
|
||||
|
||||
conn.commit()
|
||||
logger.info("[DB] Tables created/verified OK")
|
||||
|
||||
@@ -122,22 +132,28 @@ def _seed_games(cursor, conn):
|
||||
"""
|
||||
Insert default game configs if they don't already exist.
|
||||
Uses INSERT OR IGNORE to be idempotent on every launch.
|
||||
Also back-fills top_prize for any existing rows where it is empty.
|
||||
"""
|
||||
defaults = [
|
||||
# name main_count main_max bonus_count bonus_max active
|
||||
("Powerball", 5, 69, 1, 26, 1),
|
||||
("Mega Millions", 5, 70, 1, 25, 1),
|
||||
("Cash 5", 5, 45, 0, 0, 1),
|
||||
("Millionaire for Life", 5, 58, 1, 5, 1),
|
||||
("Bank a Million", 6, 40, 1, 40, 1),
|
||||
# name mc mm bc bm active top_prize
|
||||
("Powerball", 5, 69, 1, 26, 1, "Jackpot (variable)"),
|
||||
("Mega Millions", 5, 70, 1, 25, 1, "Jackpot (variable)"),
|
||||
("Cash 5", 5, 45, 0, 0, 1, "Jackpot from $200K"),
|
||||
("Millionaire for Life", 5, 58, 1, 5, 1, "$1M/yr for life"),
|
||||
("Bank a Million", 6, 40, 1, 40, 1, "$1M after taxes"),
|
||||
]
|
||||
|
||||
for row in defaults:
|
||||
cursor.execute("""
|
||||
INSERT OR IGNORE INTO games
|
||||
(name, main_count, main_max, bonus_count, bonus_max, active)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
(name, main_count, main_max, bonus_count, bonus_max, active, top_prize)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
""", row)
|
||||
# Back-fill top_prize for rows inserted before this column existed
|
||||
cursor.execute(
|
||||
"UPDATE games SET top_prize = ? WHERE name = ? AND top_prize = ''",
|
||||
(row[6], row[0]),
|
||||
)
|
||||
|
||||
inserted = conn.total_changes
|
||||
conn.commit()
|
||||
|
||||
Reference in New Issue
Block a user