<fix>[ai,db]: add error code 10134 + V5.5.12 DB migrations#3373
<fix>[ai,db]: add error code 10134 + V5.5.12 DB migrations#3373MatheMatrix wants to merge 1 commit into5.5.12from
Conversation
…tions - Add missing ORG_ZSTACK_AI_10134 constant to CloudOperationsErrorCode (required by ZSTAC-80991 GPU count validation in premium) - Add V5.5.12 schema migration: - ModelEvaluationTaskVO.targetQueueKey (ZSTAC-68709 eval queue) - ModelServiceVO.deleted soft-delete flag (ZSTAC-70478) Resolves: ZSTAC-80991, ZSTAC-68709, ZSTAC-70478 Change-Id: Iabc8f5e2d4c9b1a3e7f6d0c5b8a2e4f1d3c6b9a8
变更概览本次变更在V5.5.12版本升级脚本中为两个数据库表添加新字段——ModelEvaluationTaskVO表添加targetQueueKey字段用于队列并发控制,ModelServiceVO表添加deleted字段用于软删除;同时在错误代码类中新增AI错误代码常量。 变更清单
代码审查工作量评估🎯 1 (简单) | ⏱️ ~8 分钟 庆祝诗
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ast-grep (0.40.5)utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.javaComment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@conf/db/upgrade/V5.5.12__schema.sql`:
- Around line 1-5: The ADD_COLUMN stored procedure constructs ALTER TABLE
without backticks, risking failures when table/column names are reserved words;
update the procedure (ADD_COLUMN) to wrap the schema, table and column
identifiers with backticks when building the ALTER TABLE string (e.g. ensure the
schema `zstack`, the tb_name and the col_name are each backtick-quoted in the
CONCAT used to form the ALTER TABLE), so calls like
ADD_COLUMN('ModelServiceVO','deleted',...) and
ADD_COLUMN('ModelEvaluationTaskVO','targetQueueKey',...) will generate safe SQL
for MySQL/GreatSQL.
| -- ZSTAC-68709: Add targetQueueKey column for evaluation task queue concurrency control | ||
| CALL ADD_COLUMN('ModelEvaluationTaskVO', 'targetQueueKey', 'VARCHAR(512)', 1, NULL); | ||
|
|
||
| -- ZSTAC-70478: Add deleted (soft-delete) column for ModelServiceVO | ||
| CALL ADD_COLUMN('ModelServiceVO', 'deleted', 'tinyint(1)', 0, '0'); |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# 查找 ADD_COLUMN 存储过程定义
echo "=== 查找 ADD_COLUMN 存储过程定义 ==="
rg -n "CREATE.*PROCEDURE.*ADD_COLUMN" --type sql -A 50
echo ""
echo "=== 尝试查找所有包含 ADD_COLUMN 的 SQL 文件 ==="
fd -e sql | head -20Repository: MatheMatrix/zstack
Length of output: 4541
🏁 Script executed:
# 验证 ADD_COLUMN 过程中表名和列名的引用方式
cat conf/db/upgrade/beforeMigrate.sql | sed -n '151,181p'Repository: MatheMatrix/zstack
Length of output: 1240
ADD_COLUMN 存储过程缺少表名和列名反引号,违反编码规范
审查过程中发现 conf/db/upgrade/beforeMigrate.sql 第 165 行中的 ADD_COLUMN 存储过程在构建 ALTER TABLE 语句时,直接拼接表名和列名而未使用反引号:
CONCAT('ALTER TABLE zstack.', tb_name, ' ADD COLUMN ', col_name, ' ', col_data_type)
这违反了编码规范:"所有表名和列名必须使用反引号包裹,以避免 MySQL 8.0 / GreatSQL 保留关键字冲突导致的语法错误"。
建议修改为:
CONCAT('ALTER TABLE `zstack`.`', tb_name, '` ADD COLUMN `', col_name, '` ', col_data_type)
当前代码中若表名或列名为 MySQL 保留关键字(如 deleted、system 等),将导致升级失败。虽然当前审查文件中的列名 targetQueueKey 和 deleted 暂不会触发此问题,但系统性的修复是必要的。
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@conf/db/upgrade/V5.5.12__schema.sql` around lines 1 - 5, The ADD_COLUMN
stored procedure constructs ALTER TABLE without backticks, risking failures when
table/column names are reserved words; update the procedure (ADD_COLUMN) to wrap
the schema, table and column identifiers with backticks when building the ALTER
TABLE string (e.g. ensure the schema `zstack`, the tb_name and the col_name are
each backtick-quoted in the CONCAT used to form the ALTER TABLE), so calls like
ADD_COLUMN('ModelServiceVO','deleted',...) and
ADD_COLUMN('ModelEvaluationTaskVO','targetQueueKey',...) will generate safe SQL
for MySQL/GreatSQL.
Summary
ORG_ZSTACK_AI_10134constant (unblocks ZSTAC-80991 GPU validation in premium)V5.5.12__schema.sqlwith:ModelEvaluationTaskVO.targetQueueKeyVARCHAR(512) (ZSTAC-68709 eval queue concurrency)ModelServiceVO.deletedtinyint(1) soft-delete flag (ZSTAC-70478)Test Plan
mvn compile -pl utilspassesResolves: ZSTAC-80991, ZSTAC-68709, ZSTAC-70478
sync from gitlab !9208