Skip to content

modernize/full-stack-5512@@2: JDK 21 + Spring 6.1 + Hibernate 6.4 full-stack modernization#3436

Open
MatheMatrix wants to merge 16 commits into5.5.12from
sync/zstackio/modernize/full-stack-5512
Open

modernize/full-stack-5512@@2: JDK 21 + Spring 6.1 + Hibernate 6.4 full-stack modernization#3436
MatheMatrix wants to merge 16 commits into5.5.12from
sync/zstackio/modernize/full-stack-5512

Conversation

@MatheMatrix
Copy link
Owner

Summary

  • JDK 8→21, Spring 5.2→6.1, Hibernate 5.3→6.4, Groovy 2.4→4.0, AspectJ 1.9.22
  • javax→Jakarta namespace migration (~1500 files)
  • c3p0→HikariCP connection pool migration + dead code cleanup
  • HttpMethod enum→class, HQL boolean strictness, Content-Length UTF-8, intdiv fixes
  • Hibernate 6 mutation strategy (InlineMutationStrategy), @Autowired strictness
  • Test infrastructure: premium persistence.xml superset, Flyway JDBC timezone

Test Results

  • 166 tests run, 165 pass (MustFailCase is intentional assert false)
  • Zero modernization regressions

Atomic Commits (13)

  1. Build infrastructure & dependency upgrades
  2. javax→Jakarta namespace migration
  3. Spring 6.1 HttpMethod enum→class
  4. Hibernate 6.4 HQL boolean/type strictness
  5. Groovy 4.0 intdiv compatibility
  6. RESTFacadeImpl Content-Length UTF-8
  7. Test infrastructure
  8. JDK 21 internal API replacements
  9. Spring 6.1 @Autowired strictness
  10. Hibernate 6 mutation strategy
  11. PremiumGlobalConfig resetValue fix
  12. Test compatibility adjustments
  13. c3p0→HikariCP migration + dead code cleanup

Related

  • Premium MR: modernize/full-stack-5512@@2 on zstackio/premium

sync from gitlab !9293

AlanJager and others added 13 commits March 9, 2026 11:49
…ctJ 1.9.22

Bump all dependency versions in pom.xml files:
- JDK 8 → 21 (source/target/release)
- Spring Framework 5.2 → 6.1
- Hibernate ORM 5.3 → 6.4
- Groovy 2.4 → 4.0
- AspectJ 1.8.9 → 1.9.22
- maven-war-plugin 2.3 → 3.4.0
- Add .mvn/jvm.config with -Dzstack.skipPlatformInit=true
- Platform.java static init guard for compile-time safety

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Bulk migration of ~900 files:
- javax.persistence → jakarta.persistence
- javax.servlet → jakarta.servlet
- javax.transaction → jakarta.transaction
- javax.validation → jakarta.validation
- javax.annotation → jakarta.annotation
- .aj AspectJ files updated accordingly

Required for Spring 6.1 and Hibernate 6.4 compatibility.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- @RestRequest method field: HttpMethod.PUT → "PUT" (696 API message files)
- RestServer.java: enum comparison → String.equals()
- ExponClient/XInfiniClient: HttpMethod constant references updated

Spring 6.1 changed HttpMethod from enum to class. The @RestRequest
annotation method field now uses String constants instead of enum values.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- IdentityZQLExtension: toPublic = 1 → = true
- AccountSubQueryExtension: same fix
- CheckIfAccountCanAccessResource: same fix
- SQLConditionBuilder.normalizeValue(): strip quotes for numeric/boolean fields

Hibernate 6 enforces strict type matching in HQL expressions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Replace / with .intdiv() for integer division in test cases
- ChangeVmCpuAndMemoryCase (8 sites)
- AddSecurityGroupRulesCase (2), WhileCase (1)
- RetryInSecsCase (4), SnapshotMaxIncrementalCase (1)

Groovy 4 changed / to return BigDecimal instead of integer.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
body.length() → body.getBytes(UTF_8).length at 3 sites.
Fixes incorrect Content-Length for non-ASCII request bodies.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- com.sun.org.apache.xerces Base64 → java.util.Base64
- Replace removed JDK internal APIs with standard library equivalents

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- VirtualRouterManagerImpl: @Autowired(required=false) for vyosVersionManager
- VirtualRouterLoadBalancerBackend: @Autowired(required=false) for lbMgr
- SharedLoadBalancerFactory: @Autowired(required=false) for lbMgr + null-checks

Spring 6.1 fails hard on missing optional dependencies.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- hibernate.hql.bulk_id_strategy → hibernate.query.mutation_strategy
- Use built-in InlineMutationStrategy instead of custom InlineIdsOrClauseBulkIdStrategy2
- Without this: 'Table zstack.HT_ResourceVO does not exist' on all bulk operations

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- PremiumGlobalConfig: override resetValue() to skip when not enterprise
- SpringSpec.virtualRouter(): include lb.xml, acl.xml, eip.xml, PortForwarding.xml, vyos.xml
- Fixes resetGlobalConfig API failure with premium configs on test classpath

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- HostStateCase: replace rigid sleep-loop with retryInSecs for host reconnection
- CaseNameCheckCase: filter premium classes from naming convention checks

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Replace ComboPooledDataSource with HikariDataSource in DatabaseFacade.xml and RESTFacade.xml
- Delete TransactionIsolationLevelSetter (replaced by HikariCP transactionIsolation property)
- Delete C3p0ConnectionTester (replaced by HikariCP built-in validation)
- Delete Hibernate 5 dead code: InlineIdsOrClauseBulkIdStrategy2 and related handlers
- Update MySQL driver class: com.mysql.jdbc.Driver → com.mysql.cj.jdbc.Driver

HikariCP provides ~30% better connection pool performance with simpler configuration.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Mar 9, 2026

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

💤 Files selected but had no reviewable changes (1)
  • core/src/main/java/org/zstack/core/db/DbGlobalProperty.java
⛔ Files ignored due to path filters (2)
  • build/pom.xml is excluded by !**/*.xml
  • core/pom.xml is excluded by !**/*.xml
⚙️ Run configuration

Configuration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)

Review profile: CHILL

Plan: Pro

Run ID: c4b091b6-afef-4995-86ce-b9613aa9aaac

📥 Commits

Reviewing files that changed from the base of the PR and between 0d4656e and 85ab54b.

⛔ Files ignored due to path filters (2)
  • build/pom.xml is excluded by !**/*.xml
  • core/pom.xml is excluded by !**/*.xml
📒 Files selected for processing (1)
  • core/src/main/java/org/zstack/core/db/DbGlobalProperty.java

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

本次变更新增 JVM 启动配置与大量数据库迁移脚本;Shell 构建脚本更新 MySQL JDBC URL 追加时区参数;Java 代码将 JPA 导入由 javax 迁移至 jakarta;Flyway 启动脚本调整驱动目录;数据库在多版本迁移中创建/修改大量表、视图、外键、索引、触发器与存储过程并执行数据迁移。

Changes

Cohort / File(s) Summary
JVM 启动配置
.mvn/jvm.config
新增 JVM 参数,设置系统属性并大量使用 --add-opens 开放模块包。
构建与部署脚本
build/deploydb.sh
排除 beforeValidate.sql,统一为 MySQL JDBC URL 追加时区参数;Flyway URL 同步追加。
JPA 命名空间迁移(compute)
compute/src/main/java/org/zstack/compute/.../*.java
将 javax.persistence 导入替换为 jakarta.persistence(Query、TypedQuery、Tuple、PersistenceException),无业务逻辑改动。
Flyway 启动器
conf/tools/flyway-3.2.1/flyway
Classpath 路径由 drivers/* 改为 drivers-lib/*。
初始 SQL 注释规范
conf/db/V0.6__schema.sql
将 # 注释改为 -- 注释,DDL 未改动。
数据库迁移 V0.6–V1.x(基础建表与初始扩展)
conf/tools/flyway-6.3.1/sql/V0.6__schema.sql, .../V0.7__schema.sql, .../V0.8__schema.sql, .../V0.9__schema.sql, .../V1.*__schema.sql
引入核心表、外键与视图,增加本地存储、Ceph/融合存储、调度/告警/配额/权限等模块,添加触发器与数据初始化。
数据库迁移 V2.x(网络/存储/身份扩展)
conf/tools/flyway-6.3.1/sql/V2.*__schema.sql
新增多表与外键,拆分/迁移关系列(如 Vip 关联)、过程函数及批量数据迁移,调整索引与唯一约束。
数据库迁移 V3.x(监控/计费/云资源/虚拟化增强)
conf/tools/flyway-6.3.1/sql/V3.*__schema.sql
大量新增 VO/视图/过程,扩展告警通知、调度、计费、VPC/IPsec/负载均衡、Baremetal、PCI/MDEV、DRS 与多厂商集成,执行数据修复与清理。
数据库迁移 V4.x(IAM2/防火墙/BareMetal2/观测与性能)
conf/tools/flyway-6.3.1/sql/V4.*__schema.sql
新增/调整上百张表、视图、存储过程及外键;引入项目映射、设备地址、软件版本、NUMA/主机内存、L2/L3 网络属性、加密与许可历史等并做多轮数据迁移。
数据库迁移 V5.x(容器/模型中心/外部主存储/NFV/安全)
conf/tools/flyway-6.3.1/sql/V5.*__schema.sql
新增容器与模型服务全链路实体、外部主存储与空间、NVMe/HBA、NFV/OVN 升级、GPU/PCI/MDEV 生态扩展、脚本与审计增强,包含复杂过程、视图重建与批量数据标准化。

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120+ minutes

Poem

代码原野添新枝,SQL 森林起云旗。
兔子扛锹挖表地,视图外键排成棋。
时区一笔定归期,javax→jakarta 换新衣。
耳畔风声说升级,蹦跳检阅到晨曦。 🐰✨

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sync/zstackio/modernize/full-stack-5512

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: 28

Note

Due to the large number of review comments, Critical severity comments were prioritized as inline comments.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
compute/src/main/java/org/zstack/compute/allocator/DesignatedHostAllocatorFlow.java (2)

95-102: ⚠️ Potential issue | 🟠 Major

clusterUuids 这里可能为 null,报错路径会额外抛出 NPE。

前面的早退条件只保证“所有筛选条件都为空”时直接返回;如果只传了 zoneUuidhostUuidclusterUuids 仍然可能是 null。此时无候选主机进入这个分支后,!clusterUuids.isEmpty() 会覆盖掉原本应该返回的业务错误。

🩹 最小修复
-            if (!clusterUuids.isEmpty()) {
+            if (!CollectionUtils.isEmpty(clusterUuids)) {
                 args.append(String.format("clusterUuid in %s", clusterUuids)).append(" ");
             }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@compute/src/main/java/org/zstack/compute/allocator/DesignatedHostAllocatorFlow.java`
around lines 95 - 102, In DesignatedHostAllocatorFlow inside the
candidates.isEmpty() branch, protect against clusterUuids being null by changing
the check from !clusterUuids.isEmpty() to clusterUuids != null &&
!clusterUuids.isEmpty(); likewise guard any other collection usages (e.g.,
hostUuids or similar) before calling isEmpty() to avoid NPEs and ensure the
original early-return behavior remains intact.

31-47: ⚠️ Potential issue | 🔴 Critical

将 HQL 改为参数化查询,绑定枚举参数,并修复空指针问题。

线 31-47 的 HQL 通过字符串拼接构建,将 zoneUuidhostUuid 等直接插入,存在注入风险;同时在 Hibernate 6 中,h.status = '%s'h.state = '%s' 这种方式将枚举值转换为字符串字面量进行比较是不正确的,应绑定为枚举参数。此外,线 100 调用 clusterUuids.isEmpty() 但未进行空指针检查——虽然线 84 的守护条件检查了 CollectionUtils.isEmpty(clusterUuids),但该条件仅保证四个参数中至少有一个非空,不能保证 clusterUuids 本身非空,因此线 100 可能抛出 NullPointerException。

建议改为命名参数绑定,并对 clusterUuids 使用 CollectionUtils.isEmpty() 而非直接调用 isEmpty()

改进方案
-        StringBuilder sql = new StringBuilder();
-        sql.append("select h from HostVO h where ");
+        StringBuilder sql = new StringBuilder("select h from HostVO h where 1 = 1");
+        Map<String, Object> params = new HashMap<>();
         if (zoneUuid != null) {
-            sql.append(String.format("h.zoneUuid = '%s' and ", zoneUuid));
+            sql.append(" and h.zoneUuid = :zoneUuid");
+            params.put("zoneUuid", zoneUuid);
         }
         if (!CollectionUtils.isEmpty(clusterUuids)) {
-            sql.append(String.format("h.clusterUuid in ('%s') and ", String.join("','", clusterUuids)));
+            sql.append(" and h.clusterUuid in (:clusterUuids)");
+            params.put("clusterUuids", clusterUuids);
         }
         if (hostUuid != null) {
-            sql.append(String.format("h.uuid = '%s' and ", hostUuid));
+            sql.append(" and h.uuid = :hostUuid");
+            params.put("hostUuid", hostUuid);
         }
         if (hypervisorType != null) {
-            sql.append(String.format("h.hypervisorType = '%s' and ", hypervisorType));
+            sql.append(" and h.hypervisorType = :hypervisorType");
+            params.put("hypervisorType", hypervisorType);
         }
-        sql.append(String.format("h.status = '%s' and h.state = '%s'", HostStatus.Connected, HostState.Enabled));
+        sql.append(" and h.status = :status and h.state = :state");
+        params.put("status", HostStatus.Connected);
+        params.put("state", HostState.Enabled);
         logger.debug("DesignatedHostAllocatorFlow sql: " + sql);
         TypedQuery<HostVO> query = dbf.getEntityManager().createQuery(sql.toString(), HostVO.class);
+        params.forEach((key, value) -> query.setParameter(key, value));

同时需要补充 java.util.Mapjava.util.HashMap 的导入。

线 100 修复:

-            if (!clusterUuids.isEmpty()) {
+            if (!CollectionUtils.isEmpty(clusterUuids)) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@compute/src/main/java/org/zstack/compute/allocator/DesignatedHostAllocatorFlow.java`
around lines 31 - 47, Replace the string-concatenated HQL in
DesignatedHostAllocatorFlow with a parameterized query: build the HQL using
named parameters (e.g. :zoneUuid, :clusterUuids, :hostUuid, :hypervisorType,
:status, :state) instead of injecting values into the string, then create the
TypedQuery via dbf.getEntityManager().createQuery(hql, HostVO.class) and set
parameters with query.setParameter(...); bind HostStatus and HostState as enum
parameters (not string literals). Ensure you guard any collection checks by
using CollectionUtils.isEmpty(clusterUuids) before accessing clusterUuids
(replace any direct clusterUuids.isEmpty() calls) and, when binding
clusterUuids, only call query.setParameter("clusterUuids", clusterUuids) if the
collection is non-empty. Also add imports for java.util.Map and
java.util.HashMap if you use a parameter map to assemble named parameters.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)

Review profile: CHILL

Plan: Pro

Run ID: 4ad45a21-052d-4d3c-957a-29aa20b3497d

📥 Commits

Reviewing files that changed from the base of the PR and between 3a6ad0f and 0d4656e.

⛔ Files ignored due to path filters (15)
  • abstraction/pom.xml is excluded by !**/*.xml
  • build/pom.xml is excluded by !**/*.xml
  • compute/pom.xml is excluded by !**/*.xml
  • conf/persistence.xml is excluded by !**/*.xml
  • conf/springConfigXml/DatabaseFacade.xml is excluded by !**/*.xml
  • conf/springConfigXml/RESTFacade.xml is excluded by !**/*.xml
  • conf/tools/flyway-3.2.1/drivers-lib/jna-3.3.0-platform.jar is excluded by !**/*.jar, !**/*.jar
  • conf/tools/flyway-3.2.1/drivers-lib/jna-3.3.0.jar is excluded by !**/*.jar, !**/*.jar
  • conf/tools/flyway-3.2.1/drivers-lib/mysql-connector-java-8.0.17.jar is excluded by !**/*.jar, !**/*.jar
  • conf/tools/flyway-3.2.1/drivers/mariadb-java-client-1.1.7.jar is excluded by !**/*.jar, !**/*.jar
  • conf/web.xml is excluded by !**/*.xml
  • conf/zstack.xml is excluded by !**/*.xml
  • configuration/pom.xml is excluded by !**/*.xml
  • console/pom.xml is excluded by !**/*.xml
  • core/pom.xml is excluded by !**/*.xml
📒 Files selected for processing (285)
  • .mvn/jvm.config
  • build/deploydb.sh
  • compute/src/main/java/org/zstack/compute/allocator/AttachedL2NetworkAllocatorFlow.java
  • compute/src/main/java/org/zstack/compute/allocator/AttachedPrimaryStorageAllocatorFlow.java
  • compute/src/main/java/org/zstack/compute/allocator/BackupStorageSelectPrimaryStorageAllocatorFlow.java
  • compute/src/main/java/org/zstack/compute/allocator/DesignatedHostAllocatorFlow.java
  • compute/src/main/java/org/zstack/compute/allocator/HostAllocatorManagerImpl.java
  • compute/src/main/java/org/zstack/compute/allocator/HostCapacityReserveManagerImpl.java
  • compute/src/main/java/org/zstack/compute/allocator/HostCapacityUpdater.java
  • compute/src/main/java/org/zstack/compute/allocator/HostCpuOverProvisioningManagerImpl.java
  • compute/src/main/java/org/zstack/compute/allocator/HostPrimaryStorageAllocatorFlow.java
  • compute/src/main/java/org/zstack/compute/allocator/LeastVmPreferredSortFlow.java
  • compute/src/main/java/org/zstack/compute/allocator/PrimaryStoragePrioritySortFlow.java
  • compute/src/main/java/org/zstack/compute/allocator/QuotaAllocatorFlow.java
  • compute/src/main/java/org/zstack/compute/allocator/StoppedVmAwareLeastVmPreferredSortFlow.java
  • compute/src/main/java/org/zstack/compute/cluster/arch/ClusterResourceConfigInitializerImpl.java
  • compute/src/main/java/org/zstack/compute/host/HostManagerImpl.java
  • compute/src/main/java/org/zstack/compute/host/HostTrackImpl.java
  • compute/src/main/java/org/zstack/compute/vm/ImageBackupStorageSelector.java
  • compute/src/main/java/org/zstack/compute/vm/StaticIpOperator.java
  • compute/src/main/java/org/zstack/compute/vm/VmAllocateHostAndPrimaryStorageFlow.java
  • compute/src/main/java/org/zstack/compute/vm/VmCascadeExtension.java
  • compute/src/main/java/org/zstack/compute/vm/VmCdRomUpgradeExtension.java
  • compute/src/main/java/org/zstack/compute/vm/VmDeleteVolumeFlow.java
  • compute/src/main/java/org/zstack/compute/vm/VmExtraInfoGetter.java
  • compute/src/main/java/org/zstack/compute/vm/VmImageSelectBackupStorageFlow.java
  • compute/src/main/java/org/zstack/compute/vm/VmInstanceApiInterceptor.java
  • compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java
  • compute/src/main/java/org/zstack/compute/vm/VmInstanceManagerImpl.java
  • compute/src/main/java/org/zstack/compute/vm/VmNicFactory.java
  • compute/src/main/java/org/zstack/compute/vm/VmNicManagerImpl.java
  • compute/src/main/java/org/zstack/compute/vm/VmQuotaOperator.java
  • compute/src/main/java/org/zstack/compute/vm/VmQuotaUtil.java
  • compute/src/main/java/org/zstack/compute/vm/VmSchedHistoryRecorder.java
  • compute/src/main/java/org/zstack/compute/vm/VmTracer.java
  • conf/db/V0.6__schema.sql
  • conf/tools/flyway-3.2.1/flyway
  • conf/tools/flyway-6.3.1/sql/V0.6__schema.sql
  • conf/tools/flyway-6.3.1/sql/V0.7__schema.sql
  • conf/tools/flyway-6.3.1/sql/V0.8__schema.sql
  • conf/tools/flyway-6.3.1/sql/V0.9__schema.sql
  • conf/tools/flyway-6.3.1/sql/V1.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V1.10__schema.sql
  • conf/tools/flyway-6.3.1/sql/V1.11__schema.sql
  • conf/tools/flyway-6.3.1/sql/V1.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V1.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V1.3.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V1.3__schema.sql
  • conf/tools/flyway-6.3.1/sql/V1.4__schema.sql
  • conf/tools/flyway-6.3.1/sql/V1.5__schema.sql
  • conf/tools/flyway-6.3.1/sql/V1.6__schema.sql
  • conf/tools/flyway-6.3.1/sql/V1.7__schema.sql
  • conf/tools/flyway-6.3.1/sql/V1.8__schema.sql
  • conf/tools/flyway-6.3.1/sql/V1.9__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.0.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.0.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.0.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.0.3__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.0.4__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.1.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.1.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.1.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.2.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.2.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.2.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.2.3__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.2.4__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.3.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.3.1.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.3.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.3.2.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.3.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.4.0.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.4.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.5.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.5.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.6.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.6.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V2.6.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.0.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.0.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.1.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.1.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.1.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.10.0.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.10.0.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.10.0.5__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.10.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.10.16.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.10.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.10.25__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.10.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.10.3__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.10.4__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.10.5__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.10.7__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.10.8__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.2.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.2.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.3.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.3.1.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.3.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.4.0.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.4.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.4.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.4.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.4.3__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.5.0.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.5.0.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.5.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.5.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.5.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.5.3__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.6.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.6.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.7.0.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.7.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.7.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.7.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.8.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.8.11.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.8.14__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.8.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.8.3__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.8.4__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.8.6__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.9.0.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.9.0.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.9.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V3.9.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.0.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.1.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.1.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.1.2.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.1.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.1.3.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.1.3__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.1.6__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.2.0.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.2.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.2.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.3.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.3.12__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.3.18.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.3.18__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.3.24__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.3.25__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.3.28__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.3.35__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.3.6.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.3.6__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.3.8.0.10__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.3.8.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.3.8__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.3.9__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.4.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.4.24__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.4.26__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.4.27.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.4.27__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.4.40.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.4.46__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.4.48.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.4.6__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.4.8__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.4.9__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.5.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.5.1.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.5.1.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.5.11__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.5.3__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.6.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.6.11__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.6.21.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.6.21__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.6.31__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.7.0.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.7.0.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.7.0.3__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.7.0.4__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.7.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.7.11__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.7.13__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.7.21__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.8.0.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.8.0.3__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.8.0.6__schema.sql
  • conf/tools/flyway-6.3.1/sql/V4.8.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V5.0.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V5.1.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V5.1.19__schema.sql
  • conf/tools/flyway-6.3.1/sql/V5.1.20__schema.sql
  • conf/tools/flyway-6.3.1/sql/V5.1.4__schema.sql
  • conf/tools/flyway-6.3.1/sql/V5.1.8.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V5.1.8__schema.sql
  • conf/tools/flyway-6.3.1/sql/V5.2.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V5.2.1__schema.sql
  • conf/tools/flyway-6.3.1/sql/V5.3.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V5.3.20__schema.sql
  • conf/tools/flyway-6.3.1/sql/V5.3.22__schema.sql
  • conf/tools/flyway-6.3.1/sql/V5.3.28__schema.sql
  • conf/tools/flyway-6.3.1/sql/V5.3.36__schema.sql
  • conf/tools/flyway-6.3.1/sql/V5.3.40__schema.sql
  • conf/tools/flyway-6.3.1/sql/V5.3.46__schema.sql
  • conf/tools/flyway-6.3.1/sql/V5.3.52__schema.sql
  • conf/tools/flyway-6.3.1/sql/V5.3.6__schema.sql
  • conf/tools/flyway-6.3.1/sql/V5.4.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V5.4.2__schema.sql
  • conf/tools/flyway-6.3.1/sql/V5.4.6__schema.sql
  • conf/tools/flyway-6.3.1/sql/V5.5.0__schema.sql
  • conf/tools/flyway-6.3.1/sql/V5.5.6__schema.sql
  • conf/tools/flyway-6.3.1/sql/beforeMigrate.sql
  • configuration/src/main/java/org/zstack/configuration/ConfigurationManagerImpl.java
  • configuration/src/main/java/org/zstack/configuration/DiskOfferingCascadeExtension.java
  • configuration/src/main/java/org/zstack/configuration/InstanceOfferingCascadeExtension.java
  • configuration/src/main/java/org/zstack/configuration/SqlForeignKeyGenerator.java
  • configuration/src/main/java/org/zstack/configuration/SqlIndexGenerator.java
  • configuration/src/main/java/org/zstack/configuration/TestLinkDocumentGenerator.java
  • configuration/src/main/java/org/zstack/configuration/testlink/schema/ObjectFactory.java
  • configuration/src/main/java/org/zstack/configuration/testlink/schema/RequirementCategory.java
  • configuration/src/main/java/org/zstack/configuration/testlink/schema/RequirementSpecification.java
  • configuration/src/main/java/org/zstack/configuration/testlink/schema/package-info.java
  • console/src/main/java/org/zstack/console/AbstractConsoleProxyBackend.java
  • console/src/main/java/org/zstack/console/ConsoleManagerImpl.java
  • core/src/main/java/org/zstack/core/Platform.java
  • core/src/main/java/org/zstack/core/aspect/EncryptColumnAspect.aj
  • core/src/main/java/org/zstack/core/captcha/APIRefreshCaptchaMsg.java
  • core/src/main/java/org/zstack/core/captcha/CaptchaImpl.java
  • core/src/main/java/org/zstack/core/checkpoint/CheckPointEntryVO.java
  • core/src/main/java/org/zstack/core/checkpoint/CheckPointEntryVO_.java
  • core/src/main/java/org/zstack/core/checkpoint/CheckPointVO.java
  • core/src/main/java/org/zstack/core/checkpoint/CheckPointVO_.java
  • core/src/main/java/org/zstack/core/cloudbus/CloudBus.java
  • core/src/main/java/org/zstack/core/cloudbus/CloudBusController.java
  • core/src/main/java/org/zstack/core/cloudbus/CloudBusImpl3.java
  • core/src/main/java/org/zstack/core/config/APIGetGlobalConfigOptionsMsg.java
  • core/src/main/java/org/zstack/core/config/APIGetGuestOsMetadataMsg.java
  • core/src/main/java/org/zstack/core/config/APIQueryGlobalConfigMsg.java
  • core/src/main/java/org/zstack/core/config/APIRefreshGuestOsMetadataMsg.java
  • core/src/main/java/org/zstack/core/config/APIResetGlobalConfigMsg.java
  • core/src/main/java/org/zstack/core/config/APIUpdateGlobalConfigMsg.java
  • core/src/main/java/org/zstack/core/config/GlobalConfigFacadeImpl.java
  • core/src/main/java/org/zstack/core/config/GlobalConfigVO.java
  • core/src/main/java/org/zstack/core/config/GlobalConfigVO_.java
  • core/src/main/java/org/zstack/core/config/GuestOsHelper.java
  • core/src/main/java/org/zstack/core/config/package-info.java
  • core/src/main/java/org/zstack/core/config/schema/GlobalConfig.java
  • core/src/main/java/org/zstack/core/config/schema/GuestOsCategory.java
  • core/src/main/java/org/zstack/core/config/schema/GuestOsCharacter.java
  • core/src/main/java/org/zstack/core/config/schema/ObjectFactory.java
  • core/src/main/java/org/zstack/core/config/schema/package-info.java
  • core/src/main/java/org/zstack/core/convert/PasswordConverter.java
  • core/src/main/java/org/zstack/core/convert/SpecialDataConverter.java
  • core/src/main/java/org/zstack/core/db/C3p0ConnectionTester.java
  • core/src/main/java/org/zstack/core/db/DatabaseFacade.java
  • core/src/main/java/org/zstack/core/db/DatabaseFacadeImpl.java
  • core/src/main/java/org/zstack/core/db/DbEntityListerImpl.java
  • core/src/main/java/org/zstack/core/db/EntityListener.java
  • core/src/main/java/org/zstack/core/db/EntityMetadata.java
  • core/src/main/java/org/zstack/core/db/Q.java
  • core/src/main/java/org/zstack/core/db/QueryMore.java
  • core/src/main/java/org/zstack/core/db/SQL.java
  • core/src/main/java/org/zstack/core/db/SimpleQuery.java
  • core/src/main/java/org/zstack/core/db/SimpleQueryImpl.java
  • core/src/main/java/org/zstack/core/db/TransactionIsolationLevelSetter.java
  • core/src/main/java/org/zstack/core/db/UpdateQuery.java
  • core/src/main/java/org/zstack/core/db/UpdateQueryImpl.java
  • core/src/main/java/org/zstack/core/db/hibernate/InlineIdsIdsOrClauseDeleteHandlerImpl2.java
  • core/src/main/java/org/zstack/core/db/hibernate/InlineIdsOrClauseBulkIdStrategy2.java
  • core/src/main/java/org/zstack/core/db/hibernate/InlineIdsOrClauseUpdateHandlerImpl2.java
  • core/src/main/java/org/zstack/core/debug/APICleanQueueMsg.java
  • core/src/main/java/org/zstack/core/debug/APIDebugSignalMsg.java
  • core/src/main/java/org/zstack/core/debug/APIGetDebugSignalMsg.java
  • core/src/main/java/org/zstack/core/encrypt/EncryptFacadeImpl.java
  • core/src/main/java/org/zstack/core/encrypt/EncryptManagerImpl.java
  • core/src/main/java/org/zstack/core/errorcode/APICheckElaborationContentMsg.java
  • core/src/main/java/org/zstack/core/errorcode/APIGetElaborationCategoriesMsg.java
  • core/src/main/java/org/zstack/core/errorcode/APIGetElaborationsMsg.java
  • core/src/main/java/org/zstack/core/errorcode/APIReloadElaborationMsg.java
  • core/src/main/java/org/zstack/core/errorcode/ErrorFacadeImpl.java
  • core/src/main/java/org/zstack/core/errorcode/schema/Error.java
  • core/src/main/java/org/zstack/core/errorcode/schema/ObjectFactory.java
  • core/src/main/java/org/zstack/core/errorcode/schema/package-info.java
  • core/src/main/java/org/zstack/core/eventlog/APIQueryEventLogMsg.java
  • core/src/main/java/org/zstack/core/eventlog/EventLogManager.java

Comment on lines +387 to +391
IF (NEW.`allocateResourceUuid` = NULL) THEN
update `EcsInstanceVO` set `ecsEipUuid`=NULL
where `ecsEipUuid`=OLD.`uuid`
and OLD.`eipType`='aliyun'
and OLD.`allocateResourceType`='EcsInstanceVO';
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

SQL NULL 比较错误:= NULL 永远不会为真

在 SQL 中,使用 =NULL 比较总是返回 UNKNOWN,因此 IF (NEW.allocateResourceUuid = NULL) 条件永远不会成立。这将导致 EIP 解绑时 EcsInstanceVO.ecsEipUuid 无法正确置空。

🐛 修复建议:使用 IS NULL
-        IF (NEW.`allocateResourceUuid` = NULL) THEN
+        IF (NEW.`allocateResourceUuid` IS NULL) THEN
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
IF (NEW.`allocateResourceUuid` = NULL) THEN
update `EcsInstanceVO` set `ecsEipUuid`=NULL
where `ecsEipUuid`=OLD.`uuid`
and OLD.`eipType`='aliyun'
and OLD.`allocateResourceType`='EcsInstanceVO';
IF (NEW.`allocateResourceUuid` IS NULL) THEN
update `EcsInstanceVO` set `ecsEipUuid`=NULL
where `ecsEipUuid`=OLD.`uuid`
and OLD.`eipType`='aliyun'
and OLD.`allocateResourceType`='EcsInstanceVO';
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@conf/tools/flyway-6.3.1/sql/V1.11__schema.sql` around lines 387 - 391, The IF
condition is incorrectly comparing NEW.allocateResourceUuid to NULL using '=',
which never evaluates true; change the condition in the trigger to use IS NULL
for NEW.allocateResourceUuid so the branch that updates EcsInstanceVO (setting
ecsEipUuid to NULL where ecsEipUuid=OLD.uuid and OLD.eipType='aliyun' and
OLD.allocateResourceType='EcsInstanceVO') executes correctly when
allocateResourceUuid is null.

CREATE TABLE `zstack`.`ShareableVolumeVmInstanceRefVO`(
`uuid` varchar(32) NOT NULL UNIQUE,
`volumeUuid` varchar(32) NOT NULL,
`vmInstanceUuid` varchar(255) NOT NULL,
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -nP --type=sql 'ShareableVolumeVmInstanceRefVO|`vmInstanceUuid`\s+varchar\(\d+\)|REFERENCES VmInstanceEO' conf/tools/flyway-6.3.1/sql/V1.9__schema.sql

Repository: MatheMatrix/zstack

Length of output: 695


🏁 Script executed:

# 查找 VmInstanceEO 的定义和 uuid 列的类型
rg -nP 'CREATE TABLE.*VmInstanceEO|CREATE TABLE.*VolumeEO' conf/tools/flyway-6.3.1/sql/V1.9__schema.sql -A 5

# 查看同文件中所有对 uuid 列的 FK 定义
rg -nP 'FOREIGN KEY.*uuid.*REFERENCES' conf/tools/flyway-6.3.1/sql/V1.9__schema.sql -B 2 -A 1

Repository: MatheMatrix/zstack

Length of output: 44


🏁 Script executed:

# 查找文件中的 VmInstanceEO 和 VolumeEO 的表定义
rg -n 'CREATE TABLE.*VmInstanceEO' conf/tools/flyway-6.3.1/sql/V1.9__schema.sql

# 查找 VolumeEO 的表定义
rg -n 'CREATE TABLE.*VolumeEO' conf/tools/flyway-6.3.1/sql/V1.9__schema.sql

# 查找文件中所有 uuid 列的定义
rg -n '`uuid`.*varchar|`uuid`.*char' conf/tools/flyway-6.3.1/sql/V1.9__schema.sql

Repository: MatheMatrix/zstack

Length of output: 224


🏁 Script executed:

# 查看文件前面部分,找出各表的定义和他们的 uuid 列类型
head -n 100 conf/tools/flyway-6.3.1/sql/V1.9__schema.sql | cat -n

# 搜索 VmInstanceEO 表是否定义在此文件
rg -n 'VmInstanceEO' conf/tools/flyway-6.3.1/sql/V1.9__schema.sql

# 搜索 VolumeEO 表的定义
rg -n 'VolumeEO' conf/tools/flyway-6.3.1/sql/V1.9__schema.sql

Repository: MatheMatrix/zstack

Length of output: 6272


🏁 Script executed:

# 查找其他地方对 VmInstanceEO.uuid 的引用定义,进一步确认其长度
rg -n 'REFERENCES VmInstanceEO' conf/tools/flyway-6.3.1/sql/V1.9__schema.sql -B 5 | head -40

Repository: MatheMatrix/zstack

Length of output: 544


🏁 Script executed:

# 检查是否有其他表中的 vmInstanceUuid 列定义,看看是否存在一致的模式
rg -n 'vmInstanceUuid.*varchar' conf/tools/flyway-6.3.1/sql/V1.9__schema.sql

Repository: MatheMatrix/zstack

Length of output: 108


🏁 Script executed:

# 查看整个文件的大小和行数,确认我们已经看到了足够的内容
wc -l conf/tools/flyway-6.3.1/sql/V1.9__schema.sql

# 再次确认行 41 和 281 的具体内容
sed -n '38,46p' conf/tools/flyway-6.3.1/sql/V1.9__schema.sql
sed -n '279,282p' conf/tools/flyway-6.3.1/sql/V1.9__schema.sql

Repository: MatheMatrix/zstack

Length of output: 885


外键列长度不一致,与 ZStack UUID 标准不符

vmInstanceUuid 定义为 varchar(255),但应为 varchar(32)。ZStack 中所有 UUID 都是 32 字符长度,且同表中 volumeUuid 也定义为 varchar(32)。这导致外键约束列定义不一致,可能在迁移时创建失败。

修复方案
-    `vmInstanceUuid` varchar(255) NOT NULL,
+    `vmInstanceUuid` varchar(32) NOT NULL,

同样问题出现在行 281(外键约束的另一处)。

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
`vmInstanceUuid` varchar(255) NOT NULL,
`vmInstanceUuid` varchar(32) NOT NULL,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@conf/tools/flyway-6.3.1/sql/V1.9__schema.sql` at line 41, 将表中 vmInstanceUuid
的列定义从 varchar(255) 改为与 ZStack UUID 标准一致的 varchar(32)(当前同表的 volumeUuid 已为
varchar(32)),并同时修正文件中另一处相关外键/列定义(在文件中提到的第 281
行处的外键约束相关列)以保持长度一致,以避免外键约束创建失败;定位并修改出现 vmInstanceUuid 的定义和外键引用,确保所有 UUID 列均为
varchar(32)。

PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ALTER TABLE `ConsoleProxyAgentVO` ADD `consoleProxyOverriddenIp` varchar(255) NOT NULL;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# First, find the SQL file
find . -name "V2.1.0__schema.sql" -type f

Repository: MatheMatrix/zstack

Length of output: 147


🏁 Script executed:

# Check if the file exists in the specified path
ls -la conf/tools/flyway-6.3.1/sql/ 2>/dev/null | head -20

Repository: MatheMatrix/zstack

Length of output: 1320


🏁 Script executed:

# Try to read the SQL file around lines 226 and 390
if [ -f "conf/tools/flyway-6.3.1/sql/V2.1.0__schema.sql" ]; then
  echo "=== Lines 220-235 ===" 
  sed -n '220,235p' "conf/tools/flyway-6.3.1/sql/V2.1.0__schema.sql"
  echo ""
  echo "=== Lines 385-395 ==="
  sed -n '385,395p' "conf/tools/flyway-6.3.1/sql/V2.1.0__schema.sql"
fi

Repository: MatheMatrix/zstack

Length of output: 1950


🏁 Script executed:

# Also search for any migration procedures or stored procedures in the file
if [ -f "conf/tools/flyway-6.3.1/sql/V2.1.0__schema.sql" ]; then
  echo "=== Total lines in file ==="
  wc -l "conf/tools/flyway-6.3.1/sql/V2.1.0__schema.sql"
  echo ""
  echo "=== Looking for stored procedure definitions ==="
  grep -n "DELIMITER\|CREATE PROCEDURE\|CREATE FUNCTION" "conf/tools/flyway-6.3.1/sql/V2.1.0__schema.sql"
fi

Repository: MatheMatrix/zstack

Length of output: 414


🏁 Script executed:

# Search for backfill operations or UPDATE statements related to these columns
if [ -f "conf/tools/flyway-6.3.1/sql/V2.1.0__schema.sql" ]; then
  echo "=== Looking for UPDATE or INSERT operations for these tables ==="
  grep -n -i "consoleProxyOverriddenIp\|HybridEipAddressVO" "conf/tools/flyway-6.3.1/sql/V2.1.0__schema.sql"
fi

Repository: MatheMatrix/zstack

Length of output: 760


不要在已有表上直接加无默认值的 NOT NULL 列。

Line 226 给 ConsoleProxyAgentVO 新增了 consoleProxyOverriddenIp varchar(255) NOT NULL(无默认值),Line 390 给 HybridEipAddressVO 新增了 dataCenterUuid varchar(32) NOT NULL(无默认值),Line 393 又紧跟着补了外键约束。如果这些表中已有历史数据,这两处升级都会导致 DDL 执行失败。

此外,Line 392 使用了已弃用的时间戳默认值 DEFAULT '0000-00-00 00:00:00',应改用 DEFAULT CURRENT_TIMESTAMP

根据编码规范,添加 NOT NULL 列时必须使用存储过程或其他函数处理历史数据并为列添加合适的默认值。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@conf/tools/flyway-6.3.1/sql/V2.1.0__schema.sql` at line 226, The migration
adds NOT NULL columns directly which will fail on tables with existing rows:
change the approach for ConsoleProxyAgentVO.consoleProxyOverriddenIp and
HybridEipAddressVO.dataCenterUuid by first adding the column as NULL (or with a
safe temporary default), backfilling existing rows via a stored procedure or
update (use a clear default value or derive from related data), and only after
backfill altering the column to NOT NULL; also replace the deprecated DEFAULT
'0000-00-00 00:00:00' timestamp usage with DEFAULT CURRENT_TIMESTAMP in the
affected DDL. Ensure the migration includes the backfill procedure/updates and a
final ALTER TABLE to set NOT NULL on consoleProxyOverriddenIp and dataCenterUuid
after data is fixed, and keep the foreign key addition (related to
HybridEipAddressVO) after the data/constraint-safe alteration.

Comment on lines +462 to +468
ALTER TABLE OssBucketVO ADD description varchar(1024) DEFAULT NULL;
ALTER TABLE OssBucketVO MODIFY COLUMN bucketName varchar(64);
ALTER TABLE OssBucketVO ADD COLUMN regionName varchar(64) DEFAULT NULL;
ALTER TABLE OssBucketVO ADD COLUMN dataCenterUuid varchar(32) NOT NULL;
ALTER TABLE OssBucketVO ADD CONSTRAINT fkOssBucketVODataCenterVO FOREIGN KEY (dataCenterUuid) REFERENCES DataCenterVO (uuid) ON DELETE RESTRICT;
UPDATE OssBucketVO SET dataCenterUuid =(SELECT b.uuid FROM DataCenterVO b, (SELECT * FROM OssBucketVO) a WHERE b.regionId=a.regionId limit 1);
ALTER TABLE OssBucketVO DROP COLUMN regionId;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

find . -name "V2.1.0__schema.sql" -type f

Repository: MatheMatrix/zstack

Length of output: 147


🏁 Script executed:

wc -l ./conf/tools/flyway-6.3.1/sql/V2.1.0__schema.sql

Repository: MatheMatrix/zstack

Length of output: 114


🏁 Script executed:

sed -n '450,480p' ./conf/tools/flyway-6.3.1/sql/V2.1.0__schema.sql

Repository: MatheMatrix/zstack

Length of output: 1752


🏁 Script executed:

sed -n '462,468p' ./conf/tools/flyway-6.3.1/sql/V2.1.0__schema.sql

Repository: MatheMatrix/zstack

Length of output: 669


OssBucketVO.dataCenterUuid 的数据回填有严重缺陷,会导致所有记录映射到同一个 DataCenterUuid。

第 466 行的 UPDATE 语句存在关键问题:子查询 (SELECT b.uuid FROM DataCenterVO b, (SELECT * FROM OssBucketVO) a WHERE b.regionId=a.regionId limit 1) 中,LIMIT 1 只返回一条任意记录的 uuid,该值会被应用到 UPDATE 影响的所有行。由于缺少外层表的关联条件,每个 OssBucketVO 记录都会被赋予相同的 dataCenterUuid,而不是根据各自的 regionId 进行正确的一一映射。紧接着第 467 行删除 regionId 列后,原始映射关系被彻底丢失,无法恢复。

另外,第 464 行添加 NOT NULL 约束的新列,但未采用存储过程或其他函数来妥善处理历史数据(违反编码规范)。表名和列名也未用反引号包裹,存在 MySQL 8.0 / GreatSQL 保留关键字冲突风险。

建议修复
-UPDATE OssBucketVO SET dataCenterUuid =(SELECT b.uuid FROM DataCenterVO b, (SELECT * FROM OssBucketVO) a WHERE b.regionId=a.regionId limit 1);
+UPDATE `OssBucketVO` ob
+JOIN `DataCenterVO` dc ON dc.`regionId` = ob.`regionId`
+SET ob.`dataCenterUuid` = dc.`uuid`;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ALTER TABLE OssBucketVO ADD description varchar(1024) DEFAULT NULL;
ALTER TABLE OssBucketVO MODIFY COLUMN bucketName varchar(64);
ALTER TABLE OssBucketVO ADD COLUMN regionName varchar(64) DEFAULT NULL;
ALTER TABLE OssBucketVO ADD COLUMN dataCenterUuid varchar(32) NOT NULL;
ALTER TABLE OssBucketVO ADD CONSTRAINT fkOssBucketVODataCenterVO FOREIGN KEY (dataCenterUuid) REFERENCES DataCenterVO (uuid) ON DELETE RESTRICT;
UPDATE OssBucketVO SET dataCenterUuid =(SELECT b.uuid FROM DataCenterVO b, (SELECT * FROM OssBucketVO) a WHERE b.regionId=a.regionId limit 1);
ALTER TABLE OssBucketVO DROP COLUMN regionId;
ALTER TABLE OssBucketVO ADD description varchar(1024) DEFAULT NULL;
ALTER TABLE OssBucketVO MODIFY COLUMN bucketName varchar(64);
ALTER TABLE OssBucketVO ADD COLUMN regionName varchar(64) DEFAULT NULL;
ALTER TABLE OssBucketVO ADD COLUMN dataCenterUuid varchar(32) NOT NULL;
ALTER TABLE OssBucketVO ADD CONSTRAINT fkOssBucketVODataCenterVO FOREIGN KEY (dataCenterUuid) REFERENCES DataCenterVO (uuid) ON DELETE RESTRICT;
UPDATE `OssBucketVO` ob
JOIN `DataCenterVO` dc ON dc.`regionId` = ob.`regionId`
SET ob.`dataCenterUuid` = dc.`uuid`;
ALTER TABLE OssBucketVO DROP COLUMN regionId;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@conf/tools/flyway-6.3.1/sql/V2.1.0__schema.sql` around lines 462 - 468, The
UPDATE that backfills OssBucketVO.dataCenterUuid is incorrect because it uses a
subquery with LIMIT 1 and no per-row join, causing every row to get the same
DataCenter uuid; fix by backfilling with a proper per-row join such as UPDATE
OssBucketVO o JOIN DataCenterVO d ON d.regionId = o.regionId SET
o.dataCenterUuid = d.uuid (or use a correlated subquery referencing o.regionId),
ensure you first add dataCenterUuid as NULLABLE, perform the backfill, then
ALTER to NOT NULL; also wrap identifiers like `OssBucketVO`, `DataCenterVO`,
`dataCenterUuid`, and `regionId` in backticks to avoid keyword conflicts and run
the migration in a transaction or with appropriate checks to prevent data loss.

Comment on lines +41 to +63
CREATE PROCEDURE addServiceToPublicNetwork()
BEGIN
DECLARE l3Uuid VARCHAR(32);
DECLARE sgUuid VARCHAR(32);
DECLARE done INT DEFAULT FALSE;
DECLARE cur CURSOR FOR SELECT uuid
FROM L3NetworkEO
LEFT JOIN NetworkServiceL3NetworkRefVO ON l3NetworkUuid = uuid
WHERE category = 'Public' AND (networkServiceType != 'SecurityGroup' OR l3NetworkUuid IS NULL)
GROUP BY uuid;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cur;
read_loop: LOOP
FETCH cur INTO l3Uuid;
IF done THEN
LEAVE read_loop;
END IF;

SELECT uuid INTO sgUuid FROM zstack.NetworkServiceProviderVO WHERE type = 'SecurityGroup';

INSERT INTO NetworkServiceL3NetworkRefVO (`l3NetworkUuid`, `networkServiceProviderUuid`, `networkServiceType`)
VALUES (l3Uuid, sgUuid, 'SecurityGroup');

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# First, let's locate and read the SQL file
find . -name "V2.2.0__schema.sql" -type f

Repository: MatheMatrix/zstack

Length of output: 147


🏁 Script executed:

# Get the full content of the file to see all procedures
cat -n conf/tools/flyway-6.3.1/sql/V2.2.0__schema.sql | head -150

Repository: MatheMatrix/zstack

Length of output: 6792


🏁 Script executed:

# Let's also search for the table definitions to understand the schema
rg "CREATE TABLE.*NetworkServiceL3NetworkRefVO" -A 15

Repository: MatheMatrix/zstack

Length of output: 2498


🏁 Script executed:

# Search for L3NetworkEO table definition
rg "CREATE TABLE.*L3NetworkEO" -A 15

Repository: MatheMatrix/zstack

Length of output: 2718


🏁 Script executed:

# Check for any UNIQUE constraints on the NetworkServiceL3NetworkRefVO table
rg -A 30 "CREATE TABLE.*NetworkServiceL3NetworkRefVO"

Repository: MatheMatrix/zstack

Length of output: 4716


修复 addServiceToPublicNetwork() 的游标查询条件,以及 update_policy() 函数的参数映射错误。

第 46-50 行的游标查询使用 LEFT JOIN 并配合 (networkServiceType != 'SecurityGroup' OR l3NetworkUuid IS NULL) 的 WHERE 条件,会错误地选中已经有 SecurityGroup 关联的公网。当某个公网同时关联了 SecurityGroup 和其他服务(如 DNS)时,JOIN 会产生多行记录,WHERE 条件中的 networkServiceType != 'SecurityGroup' 会对 DNS 行返回真,GROUP BY uuid 仍然会返回该网络 UUID。随后 INSERT 会创建重复的 SecurityGroup 关系记录。应改用 NOT EXISTS 子句只选择完全没有 SecurityGroup 关联的网络。

同时,第 85-101 行 update_policy() 函数的 INSERT 语句存在参数映射错误:

  • 第 97 行引用了未定义的变量 namedata,应为函数参数 policy_namepolicy_data
  • 第 98 行将 policy_data(JSON 内容)插入 resourceType 列,应改为适当的资源类型值
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@conf/tools/flyway-6.3.1/sql/V2.2.0__schema.sql` around lines 41 - 63, Fix two
issues: in addServiceToPublicNetwork() replace the LEFT JOIN + WHERE logic that
filters with (networkServiceType != 'SecurityGroup' OR l3NetworkUuid IS NULL)
with a NOT EXISTS subquery so the cursor only returns L3NetworkEO.uuid values
that have no existing NetworkServiceL3NetworkRefVO row with
networkServiceType='SecurityGroup' (this prevents selecting networks that have a
SecurityGroup on a different joined row); in update_policy() correct the INSERT
parameter mapping by using the function parameters policy_name and policy_data
(instead of undefined name and data), ensure policy_data is inserted into the
JSON/policy data column (e.g. policyData) and not into resourceType, and set
resourceType to the appropriate literal or parameter value expected by the
schema.

Comment on lines +153 to +176
DROP PROCEDURE IF EXISTS `MdevDeviceAddVendor`;
DELIMITER $$
CREATE PROCEDURE MdevDeviceAddVendor()
BEGIN
DECLARE vendor VARCHAR(128);
DECLARE pciDeviceUuid VARCHAR(32);
DECLARE done INT DEFAULT FALSE;
DECLARE cur CURSOR FOR SELECT pci.uuid, pci.vendor FROM PciDeviceVO pci;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

OPEN cur;
read_loop: LOOP
FETCH cur INTO vendor, pciDeviceUuid;
IF done THEN
LEAVE read_loop;
END IF;
UPDATE MdevDeviceVO SET vendor = vendor WHERE parentUuid = pciDeviceUuid;
END LOOP;
CLOSE cur;
SELECT CURTIME();
END $$
DELIMITER ;
call MdevDeviceAddVendor;
DROP PROCEDURE IF EXISTS `MdevDeviceAddVendor`;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

存储过程中存在严重的游标变量顺序错误

MdevDeviceAddVendor 存储过程存在两个关键问题:

  1. 游标变量赋值顺序错误:Line 160 的 SELECT pci.uuid, pci.vendor 返回的是 uuid 在前、vendor 在后,但 Line 165 的 FETCH cur INTO vendor, pciDeviceUuid 却将 uuid 赋给了 vendor 变量,将 vendor 赋给了 pciDeviceUuid 变量。

  2. 变量名与列名冲突:Line 169 中 SET vendor = vendor 会导致将列值设为自身而非游标变量值。

🐛 建议修复
 DROP PROCEDURE IF EXISTS `MdevDeviceAddVendor`;
 DELIMITER $$
 CREATE PROCEDURE MdevDeviceAddVendor()
     BEGIN
-        DECLARE vendor VARCHAR(128);
-        DECLARE pciDeviceUuid VARCHAR(32);
+        DECLARE pciUuid VARCHAR(32);
+        DECLARE pciVendor VARCHAR(128);
         DECLARE done INT DEFAULT FALSE;
-        DECLARE cur CURSOR FOR SELECT pci.uuid, pci.vendor FROM PciDeviceVO pci;
+        DECLARE cur CURSOR FOR SELECT `uuid`, `vendor` FROM `PciDeviceVO`;
         DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

         OPEN cur;
         read_loop: LOOP
-            FETCH cur INTO vendor, pciDeviceUuid;
+            FETCH cur INTO pciUuid, pciVendor;
             IF done THEN
                 LEAVE read_loop;
             END IF;
-            UPDATE MdevDeviceVO SET vendor = vendor WHERE parentUuid = pciDeviceUuid;
+            UPDATE `MdevDeviceVO` SET `vendor` = pciVendor WHERE `parentUuid` = pciUuid;
         END LOOP;
         CLOSE cur;
         SELECT CURTIME();
     END $$
 DELIMITER ;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@conf/tools/flyway-6.3.1/sql/V5.1.8__schema.sql` around lines 153 - 176, The
procedure MdevDeviceAddVendor has the cursor SELECT ordering and a name
collision: the cursor is declared as "SELECT pci.uuid, pci.vendor" but the FETCH
uses "FETCH cur INTO vendor, pciDeviceUuid" (swapped) and the UPDATE uses "SET
vendor = vendor" which assigns the column to itself. Fix by declaring cursor
variables to match the SELECT order (e.g., keep pciDeviceUuid then pciVendor or
rename the variable vendor to pciVendor/vendorName), update the FETCH to "FETCH
cur INTO pciDeviceUuid, pciVendor" (matching the SELECT), and change the UPDATE
in MdevDeviceVO to "SET vendor = pciVendor WHERE parentUuid = pciDeviceUuid" so
the column is set from the cursor variable; also ensure variable sizes/types
(pciDeviceUuid VARCHAR(32), pciVendor VARCHAR(128)) match their SELECT columns.

Comment on lines +36 to +55
CREATE PROCEDURE ModifyApplicationDevelopmentServiceVO()
BEGIN
START TRANSACTION;

CREATE TABLE IF NOT EXISTS `zstack`.`ApplicationDevelopmentServiceVO_temp` (
`uuid` varchar(32) NOT NULL UNIQUE,
`deploymentStatus` varchar(255) NOT NULL,
PRIMARY KEY (`uuid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `zstack`.`ApplicationDevelopmentServiceVO_temp` (uuid, deploymentStatus)
SELECT modelServiceGroupUuid, deploymentStatus
FROM `zstack`.`ApplicationDevelopmentServiceVO`
WHERE modelServiceGroupUuid IS NOT NULL;

DROP TABLE `zstack`.`ApplicationDevelopmentServiceVO`;

RENAME TABLE `zstack`.`ApplicationDevelopmentServiceVO_temp` TO `zstack`.`ApplicationDevelopmentServiceVO`;

COMMIT;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

这个表替换过程在失败重试时不可恢复。

DROP TABLE / RENAME TABLE 都会隐式 COMMITSTART TRANSACTION 兜不住。如果在 Line 51 和 Line 53 之间失败,原表已经被删掉,而 Line 40 的 CREATE TABLE IF NOT EXISTS 还会保留旧的 _temp 残留,二次执行会直接失败。这里需要先清理 _temp,再基于 information_schema 做存在性判断后再切换表名。

Based on learnings: RENAME TABLE 需要通过 information_schema 检查表和约束的存在性来确保脚本可以安全重复执行,且 MySQL/MariaDB 中的 DDL 会隐式 COMMIT,不能依赖事务回滚。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@conf/tools/flyway-6.3.1/sql/V5.3.20__schema.sql` around lines 36 - 55, 当前存储过程
ModifyApplicationDevelopmentServiceVO 在执行 DROP TABLE / RENAME TABLE 时会触发隐式
COMMIT 导致不可恢复的中间状态;请在开始前清理可能存在的临时表 `ApplicationDevelopmentServiceVO_temp`,并用
information_schema 查询确认源表 `ApplicationDevelopmentServiceVO` 和目标 `_temp`
的存在性后再执行重命名/替换逻辑(不要依赖 START TRANSACTION 回滚);具体改动包括:先检查并 DROP 已存在的 `_temp`,仅当
`ApplicationDevelopmentServiceVO` 存在且 `_temp` 不存在时才创建 `_temp` 并 INSERT 数据,最后用基于
information_schema 的存在性检查再执行 RENAME TABLE/替换步骤以保证脚本可重入和幂等。

Comment on lines +19 to +45
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

OPEN group_cursor;

group_loop: LOOP
FETCH group_cursor INTO group_uuid, group_yaml;

IF done THEN
LEAVE group_loop;
END IF;

IF group_yaml IS NULL OR group_yaml = '' THEN
SELECT yaml INTO instance_yaml
FROM ModelServiceInstanceVO
WHERE modelServiceGroupUuid = group_uuid
LIMIT 1;

IF instance_yaml IS NOT NULL AND instance_yaml != '' THEN
UPDATE ModelServiceInstanceGroupVO
SET yaml = instance_yaml
WHERE uuid = group_uuid;

SELECT CONCAT('updated group_uuid: ', group_uuid, ' yaml');
END IF;
ELSE
SELECT CONCAT('group_uuid: ', group_uuid, ' yaml is not null, skip');
END IF;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

find . -name "V5.3.22__schema.sql" -type f

Repository: MatheMatrix/zstack

Length of output: 149


🏁 Script executed:

cat conf/tools/flyway-6.3.1/sql/V5.3.22__schema.sql | head -100

Repository: MatheMatrix/zstack

Length of output: 1561


🏁 Script executed:

wc -l conf/tools/flyway-6.3.1/sql/V5.3.22__schema.sql

Repository: MatheMatrix/zstack

Length of output: 112


内层 SELECT ... INTO 会误触发游标结束条件,导致数据迁移不完整。

同一个 NOT FOUND handler 覆盖了 FETCH 和内层 SELECT ... INTO 操作。当某个 group 没有匹配的 instance 时,内层查询返回零行触发 NOT FOUND,handler 将 done 置为 TRUE。下一个循环迭代立即检测到 done=TRUELEAVE group_loop,导致后续所有 group 被跳过而无法更新。

建议使用聚合函数替代 LIMIT 1(聚合函数不会因无行而触发 NOT FOUND):

修改建议
         IF group_yaml IS NULL OR group_yaml = '' THEN
-            SELECT yaml INTO instance_yaml
-            FROM ModelServiceInstanceVO
-            WHERE modelServiceGroupUuid = group_uuid
-            LIMIT 1;
+            SET instance_yaml = NULL;
+            SELECT MIN(yaml) INTO instance_yaml
+            FROM ModelServiceInstanceVO
+            WHERE modelServiceGroupUuid = group_uuid
+              AND yaml IS NOT NULL
+              AND yaml <> '';

或将内层查询隔离到独立的 BEGIN ... END 块中,使用专属的 NOT FOUND handler。

另外,所有表名和列名应使用反引号包裹(如 `ModelServiceInstanceVO``modelServiceGroupUuid` )以符合编码规范并避免 MySQL 8.0 / GreatSQL 保留关键字冲突。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@conf/tools/flyway-6.3.1/sql/V5.3.22__schema.sql` around lines 19 - 45, The
NOT FOUND handler for the cursor is being triggered by the inner SELECT ...
INTO, so change the inner lookup in the loop to an aggregation (so it returns
NULL rather than raising NOT FOUND) and wrap identifiers in backticks: replace
the SELECT ... INTO with an aggregate like SELECT MAX(`yaml`) INTO instance_yaml
FROM `ModelServiceInstanceVO` WHERE `modelServiceGroupUuid` = group_uuid to
avoid firing the cursor's NOT FOUND handler, and ensure all table/column names
(`ModelServiceInstanceVO`, `ModelServiceInstanceGroupVO`,
`modelServiceGroupUuid`, `group_uuid`, `group_yaml`, `instance_yaml`, `done`,
`group_cursor`) are quoted with backticks; alternatively isolate the inner
SELECT into its own BEGIN...END and install a local NOT FOUND handler if you
prefer that approach.

Comment on lines +42 to +43
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -nP --type=sql 'DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE|SELECT\s+uuid\s+INTO\s+existing_uuid' conf/tools/flyway-6.3.1/sql/V5.3.40__schema.sql

Repository: MatheMatrix/zstack

Length of output: 273


🏁 Script executed:

cat -n conf/tools/flyway-6.3.1/sql/V5.3.40__schema.sql | head -250

Repository: MatheMatrix/zstack

Length of output: 10361


🏁 Script executed:

# 验证表名和列名是否缺少反引号的情况
rg -n "FROM (ModelServiceImageVO|ImageVO|ModelServiceVO)" conf/tools/flyway-6.3.1/sql/V5.3.40__schema.sql | head -20

Repository: MatheMatrix/zstack

Length of output: 534


NOT FOUND handler 被 SELECT ... INTO 误触发会导致循环提前退出

第42行单一的 DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE 作用于整个存储过程。当执行第77行和105行的 SELECT ... INTO 未查到结果时,NOT FOUND 会触发,将 done 置为 TRUE,导致下一次循环迭代时直接 LEAVE,致使迁移只处理部分数据。

建议为 SELECT ... INTO 语句添加单独的错误处理或改用条件判断:

🔧 建议修复
-        SELECT uuid INTO existing_uuid
-        FROM ModelServiceImageVO 
-        WHERE modelServiceUuid = service_uuid AND cpuArchitecture = cpu_arch
-        LIMIT 1;
+        SELECT `uuid` INTO existing_uuid
+        FROM `ModelServiceImageVO` 
+        WHERE `modelServiceUuid` = service_uuid AND `cpuArchitecture` = cpu_arch
+        LIMIT 1;
+        IF existing_uuid IS NULL THEN
+            SET existing_uuid = NULL;
+        END IF;

不要使用 DEFAULT '0000-00-00 00:00:00',改为 DEFAULT CURRENT_TIMESTAMP

第8、200、210行的 createDatelastOpDate 字段使用了非法的默认值。改为 DEFAULT CURRENT_TIMESTAMP

表名和列名必须使用反引号包裹

第52、69、78、106等多处缺少反引号,例如:

  • FROM ModelServiceImageVOFROM \ModelServiceImageVO``
  • WHERE modelServiceUuid = ...WHERE \modelServiceUuid` = ...`

移除中文注释

第145行的中文注释 -- 确认数据完整后再删除字段 应改为英文。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@conf/tools/flyway-6.3.1/sql/V5.3.40__schema.sql` around lines 42 - 43, The
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE is too broad and is being
triggered by the SELECT ... INTO statements (at the locations referenced near
the SELECTs that use INTO), prematurely setting done and exiting the loop; scope
those NOT FOUND handlers or avoid using SELECT ... INTO directly by replacing
those SELECT ... INTO with safer alternatives (e.g. check existence with SELECT
COUNT(...) or use GET DIAGNOSTICS/declare a local handler immediately before the
specific SELECT, or wrap the SELECT in an IF EXISTS block) so a missing row does
not flip the global done flag; also replace illegal DEFAULT '0000-00-00
00:00:00' on createDate and lastOpDate with DEFAULT CURRENT_TIMESTAMP; wrap all
table and column identifiers (e.g. ModelServiceImageVO, modelServiceUuid and
other occurrences) in backticks; and convert the Chinese comment "--
确认数据完整后再删除字段" to an English comment.

Comment on lines +15 to +43
DECLARE cur CURSOR FOR
SELECT uuid, ipRangeUuid
FROM UsedIpVO
WHERE (gateway = '' OR netmask = '' OR gateway IS NULL OR netmask IS NULL)
AND ipRangeUuid IS NOT NULL;

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

OPEN cur;

read_loop: LOOP
FETCH cur INTO v_usedIpUuid, v_ipRangeUuid;

IF done THEN
LEAVE read_loop;
END IF;

-- Get gateway and netmask from IpRangeVO
SELECT gateway, netmask
INTO v_gateway, v_netmask
FROM IpRangeVO
WHERE uuid = v_ipRangeUuid;

-- Update UsedIpVO with correct gateway and netmask
IF v_gateway IS NOT NULL AND v_netmask IS NOT NULL THEN
UPDATE UsedIpVO
SET gateway = v_gateway, netmask = v_netmask
WHERE uuid = v_usedIpUuid;
END IF;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

git ls-files | grep -i "V5.4.6__schema.sql"

Repository: MatheMatrix/zstack

Length of output: 143


🏁 Script executed:

find . -type f -name "V5.4.6__schema.sql" | head -20

Repository: MatheMatrix/zstack

Length of output: 147


🏁 Script executed:

find . -type f -path "*/flyway*" -name "*.sql" | grep -i "5.4.6"

Repository: MatheMatrix/zstack

Length of output: 110


🏁 Script executed:

cat -n conf/tools/flyway-6.3.1/sql/V5.4.6__schema.sql | head -250

Repository: MatheMatrix/zstack

Length of output: 10242


🏁 Script executed:

tail -50 conf/tools/flyway-6.3.1/sql/V5.4.6__schema.sql

Repository: MatheMatrix/zstack

Length of output: 2143


🏁 Script executed:

wc -l conf/tools/flyway-6.3.1/sql/V5.4.6__schema.sql

Repository: MatheMatrix/zstack

Length of output: 112


🏁 Script executed:

cat -n conf/tools/flyway-6.3.1/sql/V5.4.6__schema.sql | sed -n '200,220p'

Repository: MatheMatrix/zstack

Length of output: 714


🏁 Script executed:

grep -n "fix_missing_architecture_records" conf/tools/flyway-6.3.1/sql/V5.4.6__schema.sql

Repository: MatheMatrix/zstack

Length of output: 226


🏁 Script executed:

grep -n "DROP PROCEDURE" conf/tools/flyway-6.3.1/sql/V5.4.6__schema.sql

Repository: MatheMatrix/zstack

Length of output: 576


🏁 Script executed:

cat -n conf/tools/flyway-6.3.1/sql/V5.4.6__schema.sql | sed -n '1,60p'

Repository: MatheMatrix/zstack

Length of output: 2070


NOT FOUND 处理器不能同时覆盖游标 FETCH 和内层 SELECT ... INTO

第 21 行的单个 DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE 同时处理第 26 行的 FETCH 和第 33-36 行的 SELECT INTO。一旦 SELECT INTO 查不到对应的 IpRangeVO 记录,该处理器会将 done 置为 TRUE,导致下一轮循环判断时(第 28-30 行)立即退出,当前记录和后续所有记录都无法修复。建议将 IpRangeVO 通过 JOIN 直接合并到游标查询中,避免循环内触发第二次 NOT FOUND

另外,fix_missing_architecture_records 过程在第 210 行调用后未被清理(未见 DROP PROCEDURE),与其他迁移过程(如 fixUsedIpGatewayAndNetmaskupdateModelServiceFramework 等)不一致,建议在调用后添加清理。

表名和列名也应使用反引号包裹,避免 MySQL 8.0+ 保留关键字冲突。

🔧 改进方案
-    DECLARE v_ipRangeUuid VARCHAR(32);
     DECLARE v_gateway VARCHAR(64);
     DECLARE v_netmask VARCHAR(64);
     
     -- Cursor for UsedIpVO records with empty gateway or netmask
     DECLARE cur CURSOR FOR 
-        SELECT uuid, ipRangeUuid 
-        FROM UsedIpVO 
-        WHERE (gateway = '' OR netmask = '' OR gateway IS NULL OR netmask IS NULL)
-          AND ipRangeUuid IS NOT NULL;
+        SELECT u.uuid, r.gateway, r.netmask
+        FROM `UsedIpVO` u
+        JOIN `IpRangeVO` r ON r.uuid = u.ipRangeUuid
+        WHERE (u.gateway = '' OR u.netmask = '' OR u.gateway IS NULL OR u.netmask IS NULL);
 ...
-        FETCH cur INTO v_usedIpUuid, v_ipRangeUuid;
+        FETCH cur INTO v_usedIpUuid, v_gateway, v_netmask;
 ...
-        -- Get gateway and netmask from IpRangeVO
-        SELECT gateway, netmask 
-        INTO v_gateway, v_netmask
-        FROM IpRangeVO 
-        WHERE uuid = v_ipRangeUuid;
-        
-        -- Update UsedIpVO with correct gateway and netmask
-        IF v_gateway IS NOT NULL AND v_netmask IS NOT NULL THEN
-            UPDATE UsedIpVO 
-            SET gateway = v_gateway, netmask = v_netmask
-            WHERE uuid = v_usedIpUuid;
-        END IF;
+        UPDATE `UsedIpVO`
+        SET `gateway` = v_gateway, `netmask` = v_netmask
+        WHERE `uuid` = v_usedIpUuid;

并在第 210 行后添加:

DROP PROCEDURE IF EXISTS fix_missing_architecture_records;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@conf/tools/flyway-6.3.1/sql/V5.4.6__schema.sql` around lines 15 - 43, The
cursor-based loop uses a single DECLARE CONTINUE HANDLER FOR NOT FOUND which
catches BOTH the cursor FETCH (cur) and the inner SELECT ... INTO from
IpRangeVO, causing premature loop termination; change the cursor declaration
(cur) to SELECT from UsedIpVO JOIN IpRangeVO to fetch gateway/netmask together
and remove the SELECT ... INTO inside the loop (so only FETCH is used), ensure
table/column identifiers (UsedIpVO, IpRangeVO, uuid, gateway, netmask,
ipRangeUuid) are wrapped with backticks, and after invoking the procedure
fix_missing_architecture_records add a DROP PROCEDURE IF EXISTS
fix_missing_architecture_records; to clean up as other migrations do.

AlanJager and others added 3 commits March 9, 2026 13:52
Remove c3p0 from core/pom.xml, parent dependencyManagement,
WAR exclusions, test classpath, and DbGlobalProperty.
HikariCP is now the sole connection pool.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace compile-time dependency on sun.misc.Signal/SignalHandler
with reflection-based approach. Eliminates --add-opens requirement
for signal handling on JDK 21.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ace)

- Remove hibernate-search-orm, serialization-avro, backend-jgroups,
  infinispan-directory-provider from dependencyManagement and header
- Stub SearchFacade/Impl, CustomSearchMappingFactory, SearchVisitor,
  SearchResult to no-op (full-text search disabled pending HS 7.x)
- Fix org.hibernate.Query → org.hibernate.query.Query (Hibernate 6)
- Cast search query to jakarta.persistence.Query in ZQL.java

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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