| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- """为 family_member_info 表添加参考件字段"""
- import pymysql
- DB_CONFIG = {
- "host": "rm-f8ze60yirdj8786u2wo.mysql.rds.aliyuncs.com",
- "port": 3306,
- "user": "root",
- "password": "csqz@20255",
- "db": "csqz-client",
- "charset": "utf8mb4",
- "cursorclass": pymysql.cursors.DictCursor,
- }
- COLUMNS = [
- ("reference_oss_url", "TEXT NULL COMMENT '参考件OSS地址'"),
- ("reference_file_name", "VARCHAR(255) NULL COMMENT '参考件文件名'"),
- ("reference_upload_time", "TIMESTAMP NULL COMMENT '参考件上传时间'"),
- ("reference_upload_uid", "INT NULL COMMENT '参考件上传人ID'"),
- ]
- def migrate():
- conn = pymysql.connect(**DB_CONFIG)
- try:
- with conn.cursor() as cursor:
- for col_name, col_def in COLUMNS:
- cursor.execute(f"SHOW COLUMNS FROM family_member_info LIKE '{col_name}'")
- if cursor.fetchone():
- print(f"Column {col_name} already exists, skipping.")
- continue
- cursor.execute(f"ALTER TABLE family_member_info ADD COLUMN {col_name} {col_def}")
- print(f"Added column {col_name}.")
- conn.commit()
- print("Migration complete.")
- finally:
- conn.close()
- if __name__ == "__main__":
- migrate()
|