ALM-2 / backend /tests /create_tables.py
ACA050's picture
Upload 520 files
2ed8996 verified
Raw
History Blame Contribute Delete
1.75 kB
"""
Create Database Tables for AegisLM
Creates all necessary tables in Neon PostgreSQL database.
"""
import asyncio
import sys
import os
# Add to backend directory to Python path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
async def create_all_tables():
"""Create all database tables."""
try:
from core.database import AsyncSessionLocal
from db_models import Base
print("🔧 Creating database tables...")
# Create all tables
async with AsyncSessionLocal() as db:
# Import all models to ensure they're registered
from db_models import user, role, api_key, evaluation
# Create all tables using sync connection
from core.database import get_sync_db
SessionLocal = get_sync_db()
sync_db = SessionLocal()
Base.metadata.create_all(sync_db)
sync_db.close()
print("✅ All database tables created successfully!")
# Verify tables exist
from sqlalchemy import text
result = await db.execute(text("""
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public'
ORDER BY table_name
"""))
tables = [row[0] for row in result.fetchall()]
print(f"📊 Available tables: {len(tables)}")
for table in tables:
print(f" - {table}")
except Exception as e:
print(f"❌ Failed to create tables: {str(e)}")
return False
return True
if __name__ == "__main__":
asyncio.run(create_all_tables())