Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions conf/db/upgrade/V5.5.12__schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,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');
Comment on lines +1 to +5
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.

Original file line number Diff line number Diff line change
Expand Up @@ -14804,6 +14804,8 @@ public class CloudOperationsErrorCode {

public static final String ORG_ZSTACK_AI_10133 = "ORG_ZSTACK_AI_10133";

public static final String ORG_ZSTACK_AI_10134 = "ORG_ZSTACK_AI_10134";

public static final String ORG_ZSTACK_CORE_CLOUDBUS_10000 = "ORG_ZSTACK_CORE_CLOUDBUS_10000";

public static final String ORG_ZSTACK_CORE_CLOUDBUS_10001 = "ORG_ZSTACK_CORE_CLOUDBUS_10001";
Expand Down