Spaces:
Running
Running
Download backend/simple_migration.py from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/simple_migration.py
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/backend/simple_migration.py
-
curl -L -o simple_migration.py https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/simple_migration.py
1.3 kB
| import psycopg2 | |
| import os | |
| # Database connection from .env | |
| db_url = "postgresql://postgres:postgres@localhost:5432/microfunnel" | |
| # Parse URL | |
| from urllib.parse import urlparse | |
| parsed = urlparse(db_url) | |
| conn = psycopg2.connect( | |
| host=parsed.hostname, | |
| port=parsed.port, | |
| user=parsed.username, | |
| password=parsed.password, | |
| database=parsed.path[1:] | |
| ) | |
| cursor = conn.cursor() | |
| # Read and execute migration | |
| with open('migrations/add_subscription_status.sql', 'r', encoding='utf-8') as f: | |
| migration_sql = f.read() | |
| print("🔧 Applying migration...") | |
| print("="*60) | |
| try: | |
| cursor.execute(migration_sql) | |
| conn.commit() | |
| print("✅ Migration applied successfully!") | |
| # 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(f"\n✅ Column verified:") | |
| print(f" Name: {row[0]}") | |
| print(f" Type: {row[1]}") | |
| print(f" Default: {row[2]}") | |
| except Exception as e: | |
| print(f"❌ Error: {e}") | |
| conn.rollback() | |
| finally: | |
| cursor.close() | |
| conn.close() | |
| print("\n" + "="*60) | |
| print("✅ MIGRATION COMPLETE") | |
| print("="*60) | |