Spaces:
Running

microfunnel-api / backend /simple_migration.py
MicroFunnel
Production-ready: Refactored codebase with Railway + Vercel config
cd61bf7
Raw History Blame Contribute Delete
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)