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:
Troll (Hermes Agent) 2026-08-05 13:42:10 +00:00
parent 7ab8388741
commit 3f9de1449c
4 changed files with 37 additions and 10 deletions

13
app.py
View file

@ -1493,3 +1493,16 @@ def init_db_command():
if __name__ == '__main__':
# Development-only entry point. Production uses gunicorn (see Dockerfile).
app.run(debug=True, host='0.0.0.0')
# Ensure the database file and expected tables exist when the app is imported by
# gunicorn in production. init_db() uses CREATE TABLE IF NOT EXISTS, so this is
# safe to run on every startup without wiping data.
with app.app_context():
try:
init_db()
except Exception:
# If the database path is not yet reachable (e.g. volume not mounted),
# defer to the first request or the explicit init-db command.
import logging
logging.getLogger('app').warning('Startup init_db() failed; database may need manual initialization.', exc_info=True)