Recovered state: integrated TrendSurferAgent, restored frontend/backend files, and cleaned up recovery scripts
This commit is contained in:
@@ -7,29 +7,50 @@ This creates the scheduler_cumulative_stats table.
|
||||
import sqlite3
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
# 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')
|
||||
sys.path.insert(0, str(backend_dir))
|
||||
|
||||
if not os.path.exists(db_path):
|
||||
print(f"❌ Database not found at {db_path}")
|
||||
sys.exit(1)
|
||||
from services.database import get_user_db_path
|
||||
|
||||
if not os.path.exists(migration_path):
|
||||
print(f"❌ Migration file not found at {migration_path}")
|
||||
sys.exit(1)
|
||||
def run_migration(user_id=None):
|
||||
if user_id:
|
||||
db_path = get_user_db_path(user_id)
|
||||
print(f"Targeting user database: {db_path}")
|
||||
else:
|
||||
print("❌ Error: user_id is required for migration.")
|
||||
return False
|
||||
|
||||
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)
|
||||
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}")
|
||||
return False
|
||||
|
||||
if not os.path.exists(migration_path):
|
||||
print(f"❌ Migration file not found at {migration_path}")
|
||||
return False
|
||||
|
||||
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()
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"❌ Error running migration: {e}")
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Run cumulative stats migration")
|
||||
parser.add_argument("--user_id", help="Target specific user ID")
|
||||
args = parser.parse_args()
|
||||
|
||||
success = run_migration(args.user_id)
|
||||
sys.exit(0 if success else 1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user