ALwrity version 0.5.5

This commit is contained in:
ajaysi
2025-08-19 21:48:33 +05:30
parent 5f104bf427
commit 74e22b421a
97 changed files with 16770 additions and 5000 deletions

View File

@@ -0,0 +1,48 @@
#!/usr/bin/env python3
"""
Script to check database tables and debug foreign key issues.
"""
import sys
import os
# Add the backend directory to the Python path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from services.database import engine
from sqlalchemy import inspect
from loguru import logger
def check_database_tables():
"""Check what tables exist in the database"""
try:
logger.info("Checking database tables...")
# Get inspector
inspector = inspect(engine)
# Get all table names
table_names = inspector.get_table_names()
logger.info(f"Found {len(table_names)} tables:")
for table_name in sorted(table_names):
logger.info(f" - {table_name}")
# Check if enhanced_content_strategies exists
if 'enhanced_content_strategies' in table_names:
logger.info("✅ enhanced_content_strategies table exists!")
# Get columns for this table
columns = inspector.get_columns('enhanced_content_strategies')
logger.info(f"Columns in enhanced_content_strategies:")
for column in columns:
logger.info(f" - {column['name']}: {column['type']}")
else:
logger.error("❌ enhanced_content_strategies table does not exist!")
except Exception as e:
logger.error(f"❌ Error checking database tables: {e}")
sys.exit(1)
if __name__ == "__main__":
check_database_tables()

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env python3
"""
Script to create all database tables in the correct order.
This ensures foreign key dependencies are satisfied.
"""
import sys
import os
# Add the backend directory to the Python path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from services.database import engine
from models.enhanced_strategy_models import Base as EnhancedStrategyBase
from models.monitoring_models import Base as MonitoringBase
from loguru import logger
def create_all_tables():
"""Create all tables in the correct order"""
try:
logger.info("Creating all database tables...")
# Step 1: Create enhanced strategy tables first
logger.info("Step 1: Creating enhanced strategy tables...")
EnhancedStrategyBase.metadata.create_all(bind=engine)
logger.info("✅ Enhanced strategy tables created!")
# Step 2: Create monitoring tables
logger.info("Step 2: Creating monitoring tables...")
MonitoringBase.metadata.create_all(bind=engine)
logger.info("✅ Monitoring tables created!")
logger.info("✅ All tables created successfully!")
except Exception as e:
logger.error(f"❌ Error creating tables: {e}")
sys.exit(1)
if __name__ == "__main__":
create_all_tables()

View File

@@ -0,0 +1,32 @@
#!/usr/bin/env python3
"""
Script to create enhanced strategy tables in the database.
Run this script to ensure all enhanced strategy tables are created before monitoring tables.
"""
import sys
import os
# Add the backend directory to the Python path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from services.database import engine
from models.enhanced_strategy_models import Base as EnhancedStrategyBase
from loguru import logger
def create_enhanced_strategy_tables():
"""Create all enhanced strategy tables"""
try:
logger.info("Creating enhanced strategy tables...")
# Create enhanced strategy tables first
EnhancedStrategyBase.metadata.create_all(bind=engine)
logger.info("✅ Enhanced strategy tables created successfully!")
except Exception as e:
logger.error(f"❌ Error creating enhanced strategy tables: {e}")
sys.exit(1)
if __name__ == "__main__":
create_enhanced_strategy_tables()

View File

@@ -0,0 +1,47 @@
#!/usr/bin/env python3
"""
Script to create monitoring tables in the database.
Run this script to ensure all monitoring-related tables are created.
"""
import sys
import os
# Add the backend directory to the Python path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from services.database import init_database, get_db_session
from models.monitoring_models import (
StrategyMonitoringPlan,
MonitoringTask,
TaskExecutionLog,
StrategyPerformanceMetrics,
StrategyActivationStatus
)
from models.enhanced_strategy_models import EnhancedContentStrategy
from loguru import logger
def create_monitoring_tables():
"""Create all monitoring-related tables"""
try:
logger.info("Creating monitoring tables...")
# Initialize database with all models
init_database()
logger.info("✅ Monitoring tables created successfully!")
# Test database connection
db_session = get_db_session()
if db_session:
logger.info("✅ Database connection test successful!")
db_session.close()
else:
logger.warning("⚠️ Database connection test failed!")
except Exception as e:
logger.error(f"❌ Error creating monitoring tables: {e}")
sys.exit(1)
if __name__ == "__main__":
create_monitoring_tables()

View File

@@ -0,0 +1,41 @@
#!/usr/bin/env python3
"""
Script to create monitoring tables directly.
"""
import sys
import os
# Add the backend directory to the Python path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from services.database import engine
from models.monitoring_models import (
StrategyMonitoringPlan,
MonitoringTask,
TaskExecutionLog,
StrategyPerformanceMetrics,
StrategyActivationStatus
)
from loguru import logger
def create_monitoring_tables_direct():
"""Create monitoring tables directly"""
try:
logger.info("Creating monitoring tables directly...")
# Create tables directly
StrategyMonitoringPlan.__table__.create(engine, checkfirst=True)
MonitoringTask.__table__.create(engine, checkfirst=True)
TaskExecutionLog.__table__.create(engine, checkfirst=True)
StrategyPerformanceMetrics.__table__.create(engine, checkfirst=True)
StrategyActivationStatus.__table__.create(engine, checkfirst=True)
logger.info("✅ Monitoring tables created successfully!")
except Exception as e:
logger.error(f"❌ Error creating monitoring tables: {e}")
sys.exit(1)
if __name__ == "__main__":
create_monitoring_tables_direct()