-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate_db.py
More file actions
38 lines (34 loc) · 1.44 KB
/
Copy pathmigrate_db.py
File metadata and controls
38 lines (34 loc) · 1.44 KB
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
from app import create_app
from models import db
from sqlalchemy import text
app = create_app()
with app.app_context():
try:
# 獲取資料庫類型
engine = db.engine
print(f"Connecting to database: {engine.url.drivername}")
# 檢查並增加 uploaded_bytes 欄位
try:
db.session.execute(text("ALTER TABLE upload_tasks ADD COLUMN uploaded_bytes BIGINT DEFAULT 0"))
db.session.commit()
print("Successfully added 'uploaded_bytes' column.")
except Exception as e:
db.session.rollback()
if "Duplicate column name" in str(e) or "already exists" in str(e).lower():
print("'uploaded_bytes' column already exists, skipping.")
else:
print(f"Error adding 'uploaded_bytes': {e}")
# 檢查並增加 speed 欄位
try:
db.session.execute(text("ALTER TABLE upload_tasks ADD COLUMN speed VARCHAR(50)"))
db.session.commit()
print("Successfully added 'speed' column.")
except Exception as e:
db.session.rollback()
if "Duplicate column name" in str(e) or "already exists" in str(e).lower():
print("'speed' column already exists, skipping.")
else:
print(f"Error adding 'speed': {e}")
print("Migration completed!")
except Exception as global_e:
print(f"Global Migration Error: {global_e}")