-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate_postgres.py
More file actions
23 lines (18 loc) · 872 Bytes
/
Copy pathmigrate_postgres.py
File metadata and controls
23 lines (18 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import sys
from sqlalchemy import create_engine, text
DATABASE_PUBLIC_URL = "postgresql://postgres:VwveDOCnQiRDIbKecOkrUCbxWQviyYFQ@mainline.proxy.rlwy.net:31273/railway"
def migrate():
print(f"Connecting to remote Postgres database...")
# We must ensure psycopg2 or similar is installed.
# FastAPI backends typically have it if they use Postgres.
try:
engine = create_engine(DATABASE_PUBLIC_URL)
with engine.begin() as conn:
print("Executing ALTER TABLE users DROP COLUMN team_id CASCADE...")
conn.execute(text("ALTER TABLE users DROP COLUMN IF EXISTS team_id CASCADE;"))
print("✅ Successfully dropped legacy team_id column from the remote database!")
except Exception as e:
print(f"❌ Migration failed: {e}")
sys.exit(1)
if __name__ == "__main__":
migrate()