Spaces:
Running
Running
Download backend/run_migration.py from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 1.65 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/run_migration.py
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/backend/run_migration.py
-
curl -L -o run_migration.py https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/run_migration.py
1.65 kB
| """ | |
| 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") | |