""" Quick migration runner using sync psycopg2 """ import psycopg2 # Connect to Supabase PostgreSQL conn = psycopg2.connect( host="aws-1-ap-northeast-1.pooler.supabase.com", port=5432, user="postgres.kmdhrrkfzonbncxvjhjj", password="vector7678", database="postgres" ) cursor = conn.cursor() print("\n" + "="*60) print("🔧 APPLYING MIGRATION: add_subscription_status") print("="*60 + "\n") # Migration SQL migration_sql = """ -- Add subscription_status column to tenants table ALTER TABLE tenants ADD COLUMN IF NOT EXISTS subscription_status VARCHAR(20) DEFAULT 'trial'; -- Update existing tenants to 'trial' status if NULL UPDATE tenants SET subscription_status = 'trial' WHERE subscription_status IS NULL; -- Create index for faster queries CREATE INDEX IF NOT EXISTS idx_tenants_subscription_status ON tenants(subscription_status); """ try: cursor.execute(migration_sql) conn.commit() print("✅ Migration applied successfully!\n") # Verify cursor.execute(""" SELECT column_name, data_type, column_default FROM information_schema.columns WHERE table_name = 'tenants' AND column_name = 'subscription_status' """) row = cursor.fetchone() if row: print("✅ Column verified:") print(f" Name: {row[0]}") print(f" Type: {row[1]}") print(f" Default: {row[2]}\n") else: print("❌ Column not found!\n") except Exception as e: print(f"❌ Error: {e}\n") conn.rollback() finally: cursor.close() conn.close() print("="*60) print("✅ MIGRATION COMPLETE") print("="*60 + "\n")