Spaces:
Running

File size: 1,654 Bytes
cd61bf7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
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")