Spaces:
Running
Running
File size: 1,303 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 | 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)
|