import sys, os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from sqlalchemy import create_engine, text
from app.config import get_settings

s = get_settings()
e = create_engine(s.database_url)
with e.connect() as conn:
    tables = conn.execute(text("SELECT tablename FROM pg_tables WHERE schemaname = 'public'")).fetchall()
    existing = {row[0] for row in tables}
    needed = ['plant_activations', 'plant_ownership_history', 'plant_cost_records',
              'plant_growth_records', 'plant_treatment_records', 'plant_health_records',
              'plant_harvest_records', 'plant_care_records', 'plant_care_schedules',
              'plant_issue_reports', 'plant_warranty_claims', 'farmer_support_tickets',
              'farmer_profiles', 'farms', 'farm_fields']
    for t in needed:
        status = "EXISTS" if t in existing else "MISSING"
        print(f"  {t}: {status}")
