Skip to content

Comments

<fix>[ai,db]: add error code 10134 + V5.5.12 DB migrations#3373

Open
MatheMatrix wants to merge 1 commit into5.5.12from
sync/ye.zou/fix/zstack-db-migrations
Open

<fix>[ai,db]: add error code 10134 + V5.5.12 DB migrations#3373
MatheMatrix wants to merge 1 commit into5.5.12from
sync/ye.zou/fix/zstack-db-migrations

Conversation

@MatheMatrix
Copy link
Owner

Summary

  • Add missing ORG_ZSTACK_AI_10134 constant (unblocks ZSTAC-80991 GPU validation in premium)
  • Create V5.5.12__schema.sql with:
    • ModelEvaluationTaskVO.targetQueueKey VARCHAR(512) (ZSTAC-68709 eval queue concurrency)
    • ModelServiceVO.deleted tinyint(1) soft-delete flag (ZSTAC-70478)

Test Plan

  • Verify mvn compile -pl utils passes
  • Verify upgrade from 5.5.6 → 5.5.12 applies new columns correctly

Resolves: ZSTAC-80991, ZSTAC-68709, ZSTAC-70478

sync from gitlab !9208

…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
@coderabbitai
Copy link

coderabbitai bot commented Feb 19, 2026

变更概览

本次变更在V5.5.12版本升级脚本中为两个数据库表添加新字段——ModelEvaluationTaskVO表添加targetQueueKey字段用于队列并发控制,ModelServiceVO表添加deleted字段用于软删除;同时在错误代码类中新增AI错误代码常量。

变更清单

变更文件组 变更摘要
数据库模式升级
conf/db/upgrade/V5.5.12__schema.sql
为ModelEvaluationTaskVO表添加targetQueueKey字段(VARCHAR(512),可空),为ModelServiceVO表添加deleted软删除标志字段(tinyint(1),默认值0)。
错误代码常量
utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java
添加新的AI错误代码常量ORG_ZSTACK_AI_10134。

代码审查工作量评估

🎯 1 (简单) | ⏱️ ~8 分钟

庆祝诗

🐰 数据库扩展添新字段,
队列控制更有序,
软删标记轻轻落,
错误代码齐声唱,
V5.5.12版本升级成!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed PR标题遵循[scope]: 格式,长度58字符(符合≤72字符要求),清晰描述了变更内容(添加错误代码+DB迁移)。
Description check ✅ Passed PR描述与变更内容相关,包含清晰的摘要、测试计划和关联问题追踪(JIRA/ZSTAC)。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sync/ye.zou/fix/zstack-db-migrations

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.java

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +1 to +5
-- 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');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 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 -20

Repository: 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 保留关键字(如 deletedsystem 等),将导致升级失败。虽然当前审查文件中的列名 targetQueueKeydeleted 暂不会触发此问题,但系统性的修复是必要的。

🤖 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants