This commit is contained in:
beabigegg
2025-09-04 18:34:05 +08:00
parent f093f4bbc2
commit 6eabdb2f07
35 changed files with 1097 additions and 212 deletions

42
update_db.py Normal file
View File

@@ -0,0 +1,42 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
更新數據庫模式,添加軟刪除字段
Author: PANJIT IT Team
"""
from app import create_app, db
if __name__ == '__main__':
app = create_app()
with app.app_context():
try:
# 檢查是否需要添加 deleted_at 字段
from sqlalchemy import text
# 檢查 deleted_at 字段是否存在MySQL語法
with db.engine.connect() as connection:
result = connection.execute(text("""
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'dt_translation_jobs'
"""))
columns = [row[0] for row in result.fetchall()]
if 'deleted_at' not in columns:
print("添加 deleted_at 字段...")
connection.execute(text("ALTER TABLE dt_translation_jobs ADD COLUMN deleted_at DATETIME DEFAULT NULL COMMENT '軟刪除時間'"))
connection.commit()
print("deleted_at 字段添加成功")
else:
print("deleted_at 字段已存在")
# 確保所有表都是最新的
db.create_all()
print("數據庫模式更新完成")
except Exception as e:
print(f"更新數據庫模式時發生錯誤: {e}")