diff --git a/app.py b/app.py index 7b8603c..dc83d69 100644 --- a/app.py +++ b/app.py @@ -1072,7 +1072,7 @@ def admin_settings(): n /= 1024 return f"{n:.2f} TB" - # Health check: verify expected columns exist. + # Health check: verify expected columns exist and expected tables exist. expected_cols = { 'id', 'created_at', 'name', 'email', 'hobbies', 'notable_facts', 'style_genre', 'extra_requests', 'vocal_gender', 'status', 'suno_title', 'suno_style', @@ -1080,16 +1080,27 @@ def admin_settings(): 'approval_notified_at', 'preview_sent_at', 'delivery_sent_at', 'square_payment_ref', 'admin_alert_email', 'player_token', 'revision_note', 'revision_count', 'operator_notes', 'stems_link' } - health = {'ok': True, 'missing_columns': [], 'message': 'Database schema looks good.'} + expected_tables = {'requests', 'revision_history'} + health = {'ok': True, 'missing_columns': [], 'missing_tables': [], 'message': 'Database schema looks good.'} try: db = get_db() + cur = db.execute("SELECT name FROM sqlite_master WHERE type='table'") + existing_tables = {row['name'] for row in cur.fetchall()} + missing_tables = sorted(expected_tables - existing_tables) + cur = db.execute('PRAGMA table_info(requests)') existing_cols = {row['name'] for row in cur.fetchall()} - missing = sorted(expected_cols - existing_cols) - if missing: - health = {'ok': False, 'missing_columns': missing, 'message': f'Missing columns: {", ".join(missing)}'} + missing_cols = sorted(expected_cols - existing_cols) + + if missing_tables or missing_cols: + parts = [] + if missing_tables: + parts.append(f"missing tables: {', '.join(missing_tables)}") + if missing_cols: + parts.append(f"missing columns: {', '.join(missing_cols)}") + health = {'ok': False, 'missing_columns': missing_cols, 'missing_tables': missing_tables, 'message': 'Database schema issues: ' + '; '.join(parts)} except Exception as e: - health = {'ok': False, 'missing_columns': [], 'message': f'Could not inspect table: {e}'} + health = {'ok': False, 'missing_columns': [], 'missing_tables': [], 'message': f'Could not inspect database: {e}'} if request.method == 'POST': action = request.form.get('action') diff --git a/templates/admin/settings.html b/templates/admin/settings.html index 9382132..7e64c87 100644 --- a/templates/admin/settings.html +++ b/templates/admin/settings.html @@ -201,17 +201,24 @@
✅ {{ health.message }}
- {% else %} + {% if not health.ok %}❌ {{ health.message }}
{% if health.missing_columns %}Missing columns: {{ health.missing_columns | join(', ') }}
+ {% endif %} + {% if health.missing_tables %} +Missing tables: {{ health.missing_tables | join(', ') }}
+ {% endif %} + {% else %} +✅ {{ health.message }}
+ - {% endif %} {% endif %}