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)