forked from aosfatos/check-up
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmigrate_db.py
More file actions
28 lines (22 loc) · 956 Bytes
/
Copy pathmigrate_db.py
File metadata and controls
28 lines (22 loc) · 956 Bytes
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
from decouple import config
from sqlalchemy import create_engine, text
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.schema import MetaData
print("Starting database migration...")
# Connect to the database
engine = create_engine(config("DATABASE_URL"))
connection = engine.connect()
# Add new columns to Entry table
try:
print("Adding description column to Entry table...")
connection.execute(text("ALTER TABLE entry ADD COLUMN IF NOT EXISTS description TEXT;"))
print("Adding body column to Entry table...")
connection.execute(text("ALTER TABLE entry ADD COLUMN IF NOT EXISTS body TEXT;"))
print("Adding tags column to Entry table...")
connection.execute(text("ALTER TABLE entry ADD COLUMN IF NOT EXISTS tags JSONB;"))
connection.commit()
print("Migration completed successfully!")
except Exception as e:
print(f"Error during migration: {e}")
finally:
connection.close()