Kamixitong/update_alembic_version.py
2025-11-19 22:49:24 +08:00

42 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import pymysql
# 数据库连接信息
host = 'localhost'
user = 'root'
password = 'taiyi1224'
database = 'kamaxitong'
try:
# 连接数据库
connection = pymysql.connect(
host=host,
user=user,
password=password,
database=database,
charset='utf8mb4'
)
with connection.cursor() as cursor:
# 先检查当前版本
cursor.execute("SELECT * FROM alembic_version")
current_version = cursor.fetchone()
print(f"Current alembic version: {current_version}")
# 更新alembic_version到最新版本使用较短的版本号
cursor.execute("UPDATE alembic_version SET version_num = %s WHERE version_num = %s", ("20241119", current_version[0]))
print("Updated alembic_version to 20241119")
connection.commit()
# 验证alembic版本
cursor.execute("SELECT * FROM alembic_version")
version_result = cursor.fetchone()
print(f"New alembic version: {version_result}")
except Exception as e:
print(f"Error: {e}")
if 'connection' in locals():
connection.rollback()
finally:
if 'connection' in locals():
connection.close()