fix: Add missing columns to daily_workflow_plans table
- Added generation_mode column (VARCHAR, default: 'llm_generation') - Added committee_agent_count column (INTEGER, default: 0) - Added fallback_used column (BOOLEAN, default: 0) Also fixed: - Imported daily_workflow_models in services/database.py to ensure models are registered - Added _create_daily_workflow_tables() to database setup - Created migration script to add columns to 35 existing databases - Fixed WorkflowError type in frontend to use constructor for proper 'name' property This resolves the 'no such column' sqlite3 errors when accessing the today-workflow API.
This commit is contained in:
70
backend/migrate_schema.py
Normal file
70
backend/migrate_schema.py
Normal file
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env python
|
||||
"""Migration script to add missing columns to daily_workflow_plans table."""
|
||||
import sqlite3
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
def migrate_database(db_path):
|
||||
"""Add missing columns to daily_workflow_plans table."""
|
||||
if not os.path.exists(db_path):
|
||||
print(f"Database not found: {db_path}")
|
||||
return False
|
||||
|
||||
conn = sqlite3.connect(db_path)
|
||||
cursor = conn.cursor()
|
||||
|
||||
try:
|
||||
# Check if columns already exist
|
||||
cursor.execute("PRAGMA table_info(daily_workflow_plans)")
|
||||
existing_cols = {row[1] for row in cursor.fetchall()}
|
||||
|
||||
columns_to_add = {
|
||||
'generation_mode': "VARCHAR(30) NOT NULL DEFAULT 'llm_generation'",
|
||||
'committee_agent_count': "INTEGER NOT NULL DEFAULT 0",
|
||||
'fallback_used': "BOOLEAN NOT NULL DEFAULT 0"
|
||||
}
|
||||
|
||||
for col_name, col_def in columns_to_add.items():
|
||||
if col_name not in existing_cols:
|
||||
alter_sql = f"ALTER TABLE daily_workflow_plans ADD COLUMN {col_name} {col_def}"
|
||||
print(f"Adding column: {col_name}")
|
||||
cursor.execute(alter_sql)
|
||||
print(f" ✓ Added {col_name}")
|
||||
else:
|
||||
print(f" - Column {col_name} already exists")
|
||||
|
||||
conn.commit()
|
||||
print("\n✅ Migration completed successfully!")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Migration failed: {e}")
|
||||
conn.rollback()
|
||||
return False
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
def find_and_migrate_databases():
|
||||
"""Find all databases and apply migrations."""
|
||||
workspace_dir = r'c:\Users\diksha rawat\Desktop\ALwrity\workspace'
|
||||
|
||||
if not os.path.exists(workspace_dir):
|
||||
print(f"Workspace directory not found: {workspace_dir}")
|
||||
return
|
||||
|
||||
# Find all .db files
|
||||
db_files = list(Path(workspace_dir).glob('**/db/*.db'))
|
||||
|
||||
if not db_files:
|
||||
print("No databases found to migrate")
|
||||
return
|
||||
|
||||
print(f"Found {len(db_files)} database(s) to migrate:\n")
|
||||
|
||||
for db_path in db_files:
|
||||
print(f"Migrating: {db_path.name}")
|
||||
migrate_database(str(db_path))
|
||||
print()
|
||||
|
||||
if __name__ == '__main__':
|
||||
find_and_migrate_databases()
|
||||
Reference in New Issue
Block a user