fix: ALTER TABLE 迁移补充 tb_fixture_param 缺失的 V2.0.3 波动参数字段
CREATE TABLE IF NOT EXISTS 不会更新已存在的旧表, 新增 ALTER TABLE ADD COLUMN 自动迁移逻辑(列已存在时忽略)
This commit is contained in:
@@ -175,6 +175,22 @@ async def _create_tables(pool: aiomysql.Pool):
|
|||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
# V2.0.3 迁移:为旧表补充波动测试参数字段
|
||||||
|
for col, col_def in [
|
||||||
|
("FarTol", "INT DEFAULT 0 COMMENT '最远容差 cm'"),
|
||||||
|
("NearTol", "INT DEFAULT 0 COMMENT '最近容差 cm'"),
|
||||||
|
("StepTol", "INT DEFAULT 0 COMMENT '步进容差 cm'"),
|
||||||
|
("BackForth", "INT DEFAULT 0 COMMENT '来回次数'"),
|
||||||
|
("NearStay", "INT DEFAULT 0 COMMENT '最近停留时间 ms'"),
|
||||||
|
("FarStay", "INT DEFAULT 0 COMMENT '最远停留时间 ms'"),
|
||||||
|
]:
|
||||||
|
try:
|
||||||
|
await cur.execute(
|
||||||
|
f"ALTER TABLE `tb_fixture_param` ADD COLUMN `{col}` {col_def}"
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
pass # 列已存在,忽略
|
||||||
|
|
||||||
# 7. 车检器测试基准参数表
|
# 7. 车检器测试基准参数表
|
||||||
await cur.execute("""
|
await cur.execute("""
|
||||||
CREATE TABLE IF NOT EXISTS `tb_vechicle_base_test` (
|
CREATE TABLE IF NOT EXISTS `tb_vechicle_base_test` (
|
||||||
|
|||||||
Reference in New Issue
Block a user