Fix 500 on customer revision when revision_history table is missing
Deployed databases can persist without the revision_history table, causing /play/<token>/revise to crash with sqlite3.OperationalError. - log_revision() now creates the table on the fly if it is missing. - app.py runs init_db() at import time (safe CREATE TABLE IF NOT EXISTS) so new deployments auto-create missing tables on startup. Bump patch version 0.4.0 -> 0.4.1.
This commit is contained in:
parent
7ab8388741
commit
3f9de1449c
4 changed files with 37 additions and 10 deletions
30
models.py
30
models.py
|
|
@ -184,15 +184,29 @@ def delete_request(request_id):
|
|||
|
||||
|
||||
def log_revision(request_id, revision_count, note, old_a=None, old_b=None, new_a=None, new_b=None):
|
||||
"""Record a revision event in the revision_history table."""
|
||||
"""Record a revision event in the revision_history table, creating the table if it is missing."""
|
||||
db = get_db()
|
||||
db.execute(
|
||||
"""INSERT INTO revision_history
|
||||
(request_id, revision_count, note, old_song_a_path, old_song_b_path, new_song_a_path, new_song_b_path)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)""",
|
||||
(request_id, revision_count, note, old_a, old_b, new_a, new_b)
|
||||
)
|
||||
db.commit()
|
||||
try:
|
||||
db.execute(
|
||||
"""INSERT INTO revision_history
|
||||
(request_id, revision_count, note, old_song_a_path, old_song_b_path, new_song_a_path, new_song_b_path)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)""",
|
||||
(request_id, revision_count, note, old_a, old_b, new_a, new_b)
|
||||
)
|
||||
db.commit()
|
||||
except sqlite3.OperationalError as e:
|
||||
if 'no such table' in str(e):
|
||||
# Schema drift: table missing. Recreate and retry once.
|
||||
db.executescript(SCHEMA)
|
||||
db.execute(
|
||||
"""INSERT INTO revision_history
|
||||
(request_id, revision_count, note, old_song_a_path, old_song_b_path, new_song_a_path, new_song_b_path)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)""",
|
||||
(request_id, revision_count, note, old_a, old_b, new_a, new_b)
|
||||
)
|
||||
db.commit()
|
||||
else:
|
||||
raise
|
||||
|
||||
|
||||
def list_revision_history(request_id):
|
||||
|
|
|
|||
Reference in a new issue