AI platform insights monitoring and website analysis monitoring services added

This commit is contained in:
ajaysi
2025-11-11 15:57:45 +05:30
parent d99c7c83a7
commit 7191c7e7f0
81 changed files with 10860 additions and 1567 deletions

View File

@@ -0,0 +1,90 @@
#!/usr/bin/env python3
"""
Fix website analysis index name conflicts.
Drops old conflicting indexes and ensures proper index names.
"""
import sys
import os
import sqlite3
from pathlib import Path
from loguru import logger
# Add the backend directory to the Python path
backend_dir = Path(__file__).parent.parent
sys.path.insert(0, str(backend_dir))
def fix_indexes():
"""Fix index name conflicts."""
db_path = backend_dir / "alwrity.db"
if not db_path.exists():
logger.error(f"Database not found at {db_path}")
return False
conn = sqlite3.connect(str(db_path))
cursor = conn.cursor()
try:
# Check for old conflicting indexes
cursor.execute("""
SELECT name, tbl_name
FROM sqlite_master
WHERE type='index'
AND name = 'idx_status'
AND tbl_name IN ('website_analysis_tasks', 'website_analysis_execution_logs')
""")
conflicting = cursor.fetchall()
if conflicting:
logger.warning(f"Found {len(conflicting)} conflicting indexes:")
for name, tbl_name in conflicting:
logger.warning(f" - {name} on {tbl_name}")
# Drop old indexes
for name, tbl_name in conflicting:
try:
cursor.execute(f"DROP INDEX IF EXISTS {name}")
logger.info(f"✅ Dropped old index: {name} on {tbl_name}")
except Exception as e:
logger.error(f"❌ Error dropping index {name}: {e}")
conn.commit()
logger.info("✅ Index conflicts resolved")
else:
logger.info("✅ No conflicting indexes found")
# Verify correct indexes exist
cursor.execute("""
SELECT name, tbl_name
FROM sqlite_master
WHERE type='index'
AND (name LIKE '%website_analysis%' OR name LIKE '%competitor_analyses%')
ORDER BY tbl_name, name
""")
indexes = cursor.fetchall()
logger.info(f"\n📋 Current website analysis indexes ({len(indexes)}):")
for name, tbl_name in indexes:
logger.info(f" - {name} on {tbl_name}")
return True
except Exception as e:
logger.error(f"Error fixing indexes: {e}")
conn.rollback()
return False
finally:
conn.close()
if __name__ == "__main__":
logger.info("🔧 Fixing website analysis index conflicts...")
success = fix_indexes()
if success:
logger.info("✅ Index fix complete. You can now restart the backend.")
sys.exit(0)
else:
logger.error("❌ Index fix failed")
sys.exit(1)

View File

@@ -0,0 +1,35 @@
#!/usr/bin/env python3
"""
Script to run the cumulative stats migration.
This creates the scheduler_cumulative_stats table.
"""
import sqlite3
import os
import sys
# Get the database path
script_dir = os.path.dirname(os.path.abspath(__file__))
backend_dir = os.path.dirname(script_dir)
db_path = os.path.join(backend_dir, 'alwrity.db')
migration_path = os.path.join(backend_dir, 'database', 'migrations', 'create_scheduler_cumulative_stats.sql')
if not os.path.exists(db_path):
print(f"❌ Database not found at {db_path}")
sys.exit(1)
if not os.path.exists(migration_path):
print(f"❌ Migration file not found at {migration_path}")
sys.exit(1)
try:
conn = sqlite3.connect(db_path)
with open(migration_path, 'r') as f:
conn.executescript(f.read())
conn.commit()
print("✅ Migration executed successfully")
conn.close()
except Exception as e:
print(f"❌ Error running migration: {e}")
sys.exit(1)

View File

@@ -0,0 +1,30 @@
#!/usr/bin/env python3
"""Verify cumulative stats table exists and has data"""
import sqlite3
import os
script_dir = os.path.dirname(os.path.abspath(__file__))
backend_dir = os.path.dirname(script_dir)
db_path = os.path.join(backend_dir, 'alwrity.db')
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# Check if table exists
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='scheduler_cumulative_stats'")
result = cursor.fetchone()
print(f"Table exists: {result is not None}")
if result:
cursor.execute("SELECT * FROM scheduler_cumulative_stats WHERE id=1")
row = cursor.fetchone()
if row:
print(f"Row data: {row}")
else:
print("Table exists but no row with id=1")
else:
print("Table does not exist")
conn.close()