1.7 KiB
1.7 KiB
Database Initialization Fix
Issue
Dashboard was showing errors:
sqlite3.OperationalError: no such table: files
Root Cause
The DatabaseReader._ensure_database() method only initialized the database if the file didn't exist:
if not self.db_path.exists():
self._initialize_database()
This caused problems when:
- Database file exists but is empty
- Database file exists but schema is outdated
- Database was created but initialization failed partway through
Fix
Changed to always run initialization (dashboard.py:129-133):
def _ensure_database(self):
"""Ensure database exists and has correct schema"""
# Always run initialization - it's safe with CREATE TABLE IF NOT EXISTS
# This ensures migrations run even if the file exists but schema is outdated
self._initialize_database()
Why This Is Safe
- CREATE TABLE IF NOT EXISTS - Won't recreate existing tables
- Migration checks - Only adds columns that don't exist
- Idempotent - Can run multiple times safely
- Auto-repair - Fixes incomplete or corrupted schemas
Benefits
✅ Database always has correct schema ✅ Migrations run automatically on startup ✅ Handles edge cases (empty files, partial schemas) ✅ No manual intervention needed ✅ Works for fresh installs and upgrades
Similar Fix Applied
The same initialization logic exists in reencode.py's StateDatabase class, which already runs migrations every time. This change brings dashboard.py in line with that behavior.
Testing
After this fix:
- Dashboard starts successfully
- Database is created if missing
- Tables are created if missing
- New columns are added via migration
- All API endpoints work properly