import sys
sys.path.append('E:/genesis-system/data/genesis-memory')
try:
    from elestio_config import PostgresConfig
    import psycopg2
    conn = psycopg2.connect(**PostgresConfig.get_connection_params())
    cur = conn.cursor()
    cur.execute("SELECT table_name FROM information_schema.tables WHERE table_schema='public'")
    tables = [r[0] for r in cur.fetchall()]
    print('TABLES:', tables)
    # Check for tradie_leads table
    if 'tradie_leads' in tables:
        cur.execute("SELECT COUNT(*) FROM tradie_leads")
        count = cur.fetchone()[0]
        print(f'tradie_leads count: {count}')
        cur.execute("SELECT business_name, phone, trade_category, suburb, state FROM tradie_leads LIMIT 5")
        for row in cur.fetchall():
            print('SAMPLE:', row)
    else:
        print('No tradie_leads table found')
    conn.close()
    print('DB_OK')
except Exception as e:
    print('DB_ERROR:', e)
