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:
ajaysi
2026-03-09 12:48:12 +05:30
parent 7747174f00
commit 9713af0c1b
8 changed files with 537 additions and 0 deletions

View File

@@ -36,6 +36,7 @@ class DatabaseSetup:
self._create_subscription_tables()
self._create_persona_tables()
self._create_onboarding_tables()
self._create_daily_workflow_tables()
if verbose:
print("✅ Essential database tables created")
@@ -114,6 +115,22 @@ class DatabaseSetup:
print(f" ⚠️ Onboarding tables failed: {e}")
return True # Non-critical
def _create_daily_workflow_tables(self) -> bool:
"""Create daily workflow tables."""
import os
verbose = os.getenv("ALWRITY_VERBOSE", "false").lower() == "true"
try:
from models.enhanced_strategy_models import Base as StrategyBase
StrategyBase.metadata.create_all(bind=engine)
if verbose:
print(" ✅ Daily workflow tables created")
return True
except Exception as e:
if verbose:
print(f" ⚠️ Daily workflow tables failed: {e}")
return True # Non-critical
def verify_tables(self) -> bool:
"""Verify that essential tables exist."""
import os

15
backend/check_cols.py Normal file
View File

@@ -0,0 +1,15 @@
import sqlite3
import os
db_path = r'workspace/workspace_user_33Gz1FPI86VDXhRY8QN4ragRFGN/db/alwrity_user_33Gz1FPI86VDXhRY8QN4ragRFGN.db'
if os.path.exists(db_path):
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
cursor.execute("PRAGMA table_info(daily_workflow_plans)")
cols = cursor.fetchall()
col_names = [c[1] for c in cols]
print("Columns:", col_names)
conn.close()
else:
print(f"Database not found at {db_path}")

32
backend/check_tables.py Normal file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/env python
import sqlite3
import os
db_path = 'alwrity.db'
if os.path.exists(db_path):
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# Check daily workflow tables
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name LIKE 'daily_%'")
daily_tables = [row[0] for row in cursor.fetchall()]
print(f"Daily workflow tables: {daily_tables}")
# Check the columns in daily_workflow_plans if it exists
if 'daily_workflow_plans' in daily_tables:
cursor.execute("PRAGMA table_info(daily_workflow_plans)")
columns = cursor.fetchall()
col_names = [col[1] for col in columns]
print(f"Columns in daily_workflow_plans: {col_names}")
# Check if generation_mode exists
if 'generation_mode' in col_names:
print("✅ generation_mode column exists")
else:
print("❌ generation_mode column missing")
else:
print("❌ daily_workflow_plans table doesn't exist")
conn.close()
else:
print(f"❌ Database file {db_path} not found")

57
backend/debug_schema.py Normal file
View File

@@ -0,0 +1,57 @@
#!/usr/bin/env python
"""Debug script to check database schema."""
import os
import sys
sys.path.insert(0, '.')
# Set up logging
os.environ['ALWRITY_VERBOSE'] = 'true'
from models.enhanced_strategy_models import Base
from models.daily_workflow_models import DailyWorkflowPlan, DailyWorkflowTask, TaskHistory
# Check what tables are registered with EnhancedStrategyBase
print("Tables registered with EnhancedStrategyBase:")
for table_name in Base.metadata.tables:
print(f" - {table_name}")
if 'daily' in table_name:
table = Base.metadata.tables[table_name]
print(f" Columns: {[col.name for col in table.columns]}")
# Now create the tables
from services.database import get_engine_for_user
test_user_id = "debug_test_user_12345"
engine = get_engine_for_user(test_user_id)
print(f"\nCreating tables for test user: {test_user_id}")
Base.metadata.create_all(bind=engine)
print("\n✅ Tables created successfully!")
# Verify the tables exist
import sqlite3
from services.database import get_user_db_path
db_path = get_user_db_path(test_user_id)
print(f"\nDatabase path: {db_path}")
if os.path.exists(db_path):
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
tables = [row[0] for row in cursor.fetchall()]
print(f"Tables in database: {tables}")
if 'daily_workflow_plans' in tables:
cursor.execute("PRAGMA table_info(daily_workflow_plans)")
columns = cursor.fetchall()
col_names = [col[1] for col in columns]
print(f"\nColumns in daily_workflow_plans:")
for col in columns:
print(f" - {col[1]} ({col[2]})")
conn.close()
else:
print(f"❌ Database not found at {db_path}")

70
backend/migrate_schema.py Normal file
View 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()

View File

@@ -22,6 +22,8 @@ from models.persona_models import Base as PersonaBase
from models.subscription_models import Base as SubscriptionBase
from models.user_business_info import Base as UserBusinessInfoBase
from models.content_asset_models import Base as ContentAssetBase
# Import daily workflow models to ensure they are registered with EnhancedStrategyBase
from models.daily_workflow_models import DailyWorkflowPlan, DailyWorkflowTask, TaskHistory
# Product Marketing models use SubscriptionBase, but import to ensure models are registered
from models.product_marketing_models import Campaign, CampaignProposal, CampaignAsset
# Product Asset models (Product Marketing Suite - product assets, not campaigns)

28
backend/verify_schema.py Normal file
View File

@@ -0,0 +1,28 @@
import sqlite3
db_path = r'c:\Users\diksha rawat\Desktop\ALwrity\workspace\workspace_alwrity\db\alwrity_alwrity.db'
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# Check tables
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name LIKE 'daily_%'")
tables = cursor.fetchall()
print(f"Daily tables: {tables}")
if tables:
cursor.execute("PRAGMA table_info(daily_workflow_plans)")
cols = cursor.fetchall()
col_names = [c[1] for c in cols]
print(f"\nColumns in daily_workflow_plans: {col_names}")
required = ['generation_mode', 'committee_agent_count', 'fallback_used']
for col in required:
if col in col_names:
print(f"{col}")
else:
print(f"{col}")
else:
print("No daily tables found")
conn.close()