41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
import pymysql
|
|
import os
|
|
|
|
DB_HOST = "mysql1.rdsmbk3ednsgnnt.rds.bj.baidubce.com"
|
|
DB_PORT = 3306
|
|
DB_NAME = "case_platform"
|
|
DB_USER = "root_dev"
|
|
DB_PASS = "Kdse89sd"
|
|
|
|
def run_migration():
|
|
try:
|
|
connection = pymysql.connect(
|
|
host=DB_HOST,
|
|
port=DB_PORT,
|
|
user=DB_USER,
|
|
password=DB_PASS,
|
|
database=DB_NAME,
|
|
charset='utf8mb4',
|
|
cursorclass=pymysql.cursors.DictCursor
|
|
)
|
|
with connection.cursor() as cursor:
|
|
# Check if assignees column exists in test_tasks
|
|
cursor.execute("SHOW COLUMNS FROM test_tasks LIKE 'assignees'")
|
|
result = cursor.fetchone()
|
|
if not result:
|
|
print("Adding 'assignees' column to 'test_tasks' table...")
|
|
cursor.execute("ALTER TABLE test_tasks ADD COLUMN assignees JSON NULL AFTER plan_id")
|
|
print("Column added successfully.")
|
|
else:
|
|
print("Column 'assignees' already exists in 'test_tasks'.")
|
|
|
|
connection.commit()
|
|
except Exception as e:
|
|
print(f"Migration failed: {e}")
|
|
finally:
|
|
if 'connection' in locals():
|
|
connection.close()
|
|
|
|
if __name__ == "__main__":
|
|
run_migration()
|