import asyncio
import os
from sqlalchemy.ext.asyncio import create_async_engine
from sqlalchemy import text

async def check_db():
    database_url = os.getenv('DATABASE_URL')
    print(f"Connecting to: {database_url[:50]}...")

    engine = create_async_engine(database_url)
    try:
        async with engine.connect() as conn:
            # List tables
            result = await conn.execute(text("""
                SELECT table_name
                FROM information_schema.tables
                WHERE table_schema = 'policy_service'
                ORDER BY table_name
            """))
            tables = [row[0] for row in result.fetchall()]
            print(f"\nTables in policy_service schema ({len(tables)}):")
            for table in tables:
                print(f"  - {table}")

            # Check if customers table exists
            if 'customers' in tables:
                result = await conn.execute(text("SELECT COUNT(*) FROM policy_service.customers"))
                count = result.scalar()
                print(f"\nCustomers count: {count}")
            else:
                print("\n❌ customers table does NOT exist!")

    except Exception as e:
        print(f"Error: {type(e).__name__}: {e}")
    finally:
        await engine.dispose()

if __name__ == "__main__":
    asyncio.run(check_db())
