from sqlalchemy import create_engine, text
from sqlalchemy.orm import sessionmaker
from config import ADMIN_CONFIG

# Database connection
engine = create_engine(ADMIN_CONFIG['DATABASE_URL'])
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
db = SessionLocal()

# Check for specific tables
tables_to_check = ['messages', 'reviews', 'bookmarks']

for table_name in tables_to_check:
    try:
        result = db.execute(text(f"""
            SELECT EXISTS (
                SELECT FROM information_schema.tables 
                WHERE table_schema = 'public' 
                AND table_name = '{table_name}'
            )
        """)).fetchone()
        
        if result and result[0]:
            print(f"Table '{table_name}' exists")
        else:
            print(f"Table '{table_name}' does not exist")
    except Exception as e:
        print(f"Error checking table '{table_name}': {e}")

db.close()