modernize/full-stack-5512@@2: JDK 21 + Spring 6.1 + Hibernate 6.4 full-stack modernization#3436
modernize/full-stack-5512@@2: JDK 21 + Spring 6.1 + Hibernate 6.4 full-stack modernization#3436MatheMatrix wants to merge 16 commits into5.5.12from
Conversation
…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>
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes. 💤 Files selected but had no reviewable changes (1)
⛔ Files ignored due to path filters (2)
⚙️ Run configurationConfiguration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml) Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (1)
You can disable this status message by setting the Use the checkbox below for a quick retry:
Walkthrough本次变更新增 JVM 启动配置与大量数据库迁移脚本;Shell 构建脚本更新 MySQL JDBC URL 追加时区参数;Java 代码将 JPA 导入由 javax 迁移至 jakarta;Flyway 启动脚本调整驱动目录;数据库在多版本迁移中创建/修改大量表、视图、外键、索引、触发器与存储过程并执行数据迁移。 Changes
Estimated code review effort🎯 5 (Critical) | ⏱️ ~120+ minutes Poem
✨ Finishing Touches🧪 Generate unit tests (beta)
|
There was a problem hiding this comment.
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。前面的早退条件只保证“所有筛选条件都为空”时直接返回;如果只传了
zoneUuid或hostUuid,clusterUuids仍然可能是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 通过字符串拼接构建,将
zoneUuid、hostUuid等直接插入,存在注入风险;同时在 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.Map和java.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
⛔ Files ignored due to path filters (15)
abstraction/pom.xmlis excluded by!**/*.xmlbuild/pom.xmlis excluded by!**/*.xmlcompute/pom.xmlis excluded by!**/*.xmlconf/persistence.xmlis excluded by!**/*.xmlconf/springConfigXml/DatabaseFacade.xmlis excluded by!**/*.xmlconf/springConfigXml/RESTFacade.xmlis excluded by!**/*.xmlconf/tools/flyway-3.2.1/drivers-lib/jna-3.3.0-platform.jaris excluded by!**/*.jar,!**/*.jarconf/tools/flyway-3.2.1/drivers-lib/jna-3.3.0.jaris excluded by!**/*.jar,!**/*.jarconf/tools/flyway-3.2.1/drivers-lib/mysql-connector-java-8.0.17.jaris excluded by!**/*.jar,!**/*.jarconf/tools/flyway-3.2.1/drivers/mariadb-java-client-1.1.7.jaris excluded by!**/*.jar,!**/*.jarconf/web.xmlis excluded by!**/*.xmlconf/zstack.xmlis excluded by!**/*.xmlconfiguration/pom.xmlis excluded by!**/*.xmlconsole/pom.xmlis excluded by!**/*.xmlcore/pom.xmlis excluded by!**/*.xml
📒 Files selected for processing (285)
.mvn/jvm.configbuild/deploydb.shcompute/src/main/java/org/zstack/compute/allocator/AttachedL2NetworkAllocatorFlow.javacompute/src/main/java/org/zstack/compute/allocator/AttachedPrimaryStorageAllocatorFlow.javacompute/src/main/java/org/zstack/compute/allocator/BackupStorageSelectPrimaryStorageAllocatorFlow.javacompute/src/main/java/org/zstack/compute/allocator/DesignatedHostAllocatorFlow.javacompute/src/main/java/org/zstack/compute/allocator/HostAllocatorManagerImpl.javacompute/src/main/java/org/zstack/compute/allocator/HostCapacityReserveManagerImpl.javacompute/src/main/java/org/zstack/compute/allocator/HostCapacityUpdater.javacompute/src/main/java/org/zstack/compute/allocator/HostCpuOverProvisioningManagerImpl.javacompute/src/main/java/org/zstack/compute/allocator/HostPrimaryStorageAllocatorFlow.javacompute/src/main/java/org/zstack/compute/allocator/LeastVmPreferredSortFlow.javacompute/src/main/java/org/zstack/compute/allocator/PrimaryStoragePrioritySortFlow.javacompute/src/main/java/org/zstack/compute/allocator/QuotaAllocatorFlow.javacompute/src/main/java/org/zstack/compute/allocator/StoppedVmAwareLeastVmPreferredSortFlow.javacompute/src/main/java/org/zstack/compute/cluster/arch/ClusterResourceConfigInitializerImpl.javacompute/src/main/java/org/zstack/compute/host/HostManagerImpl.javacompute/src/main/java/org/zstack/compute/host/HostTrackImpl.javacompute/src/main/java/org/zstack/compute/vm/ImageBackupStorageSelector.javacompute/src/main/java/org/zstack/compute/vm/StaticIpOperator.javacompute/src/main/java/org/zstack/compute/vm/VmAllocateHostAndPrimaryStorageFlow.javacompute/src/main/java/org/zstack/compute/vm/VmCascadeExtension.javacompute/src/main/java/org/zstack/compute/vm/VmCdRomUpgradeExtension.javacompute/src/main/java/org/zstack/compute/vm/VmDeleteVolumeFlow.javacompute/src/main/java/org/zstack/compute/vm/VmExtraInfoGetter.javacompute/src/main/java/org/zstack/compute/vm/VmImageSelectBackupStorageFlow.javacompute/src/main/java/org/zstack/compute/vm/VmInstanceApiInterceptor.javacompute/src/main/java/org/zstack/compute/vm/VmInstanceBase.javacompute/src/main/java/org/zstack/compute/vm/VmInstanceManagerImpl.javacompute/src/main/java/org/zstack/compute/vm/VmNicFactory.javacompute/src/main/java/org/zstack/compute/vm/VmNicManagerImpl.javacompute/src/main/java/org/zstack/compute/vm/VmQuotaOperator.javacompute/src/main/java/org/zstack/compute/vm/VmQuotaUtil.javacompute/src/main/java/org/zstack/compute/vm/VmSchedHistoryRecorder.javacompute/src/main/java/org/zstack/compute/vm/VmTracer.javaconf/db/V0.6__schema.sqlconf/tools/flyway-3.2.1/flywayconf/tools/flyway-6.3.1/sql/V0.6__schema.sqlconf/tools/flyway-6.3.1/sql/V0.7__schema.sqlconf/tools/flyway-6.3.1/sql/V0.8__schema.sqlconf/tools/flyway-6.3.1/sql/V0.9__schema.sqlconf/tools/flyway-6.3.1/sql/V1.0__schema.sqlconf/tools/flyway-6.3.1/sql/V1.10__schema.sqlconf/tools/flyway-6.3.1/sql/V1.11__schema.sqlconf/tools/flyway-6.3.1/sql/V1.1__schema.sqlconf/tools/flyway-6.3.1/sql/V1.2__schema.sqlconf/tools/flyway-6.3.1/sql/V1.3.1__schema.sqlconf/tools/flyway-6.3.1/sql/V1.3__schema.sqlconf/tools/flyway-6.3.1/sql/V1.4__schema.sqlconf/tools/flyway-6.3.1/sql/V1.5__schema.sqlconf/tools/flyway-6.3.1/sql/V1.6__schema.sqlconf/tools/flyway-6.3.1/sql/V1.7__schema.sqlconf/tools/flyway-6.3.1/sql/V1.8__schema.sqlconf/tools/flyway-6.3.1/sql/V1.9__schema.sqlconf/tools/flyway-6.3.1/sql/V2.0.0__schema.sqlconf/tools/flyway-6.3.1/sql/V2.0.1__schema.sqlconf/tools/flyway-6.3.1/sql/V2.0.2__schema.sqlconf/tools/flyway-6.3.1/sql/V2.0.3__schema.sqlconf/tools/flyway-6.3.1/sql/V2.0.4__schema.sqlconf/tools/flyway-6.3.1/sql/V2.1.0__schema.sqlconf/tools/flyway-6.3.1/sql/V2.1.1__schema.sqlconf/tools/flyway-6.3.1/sql/V2.1.2__schema.sqlconf/tools/flyway-6.3.1/sql/V2.2.0__schema.sqlconf/tools/flyway-6.3.1/sql/V2.2.1__schema.sqlconf/tools/flyway-6.3.1/sql/V2.2.2__schema.sqlconf/tools/flyway-6.3.1/sql/V2.2.3__schema.sqlconf/tools/flyway-6.3.1/sql/V2.2.4__schema.sqlconf/tools/flyway-6.3.1/sql/V2.3.0__schema.sqlconf/tools/flyway-6.3.1/sql/V2.3.1.2__schema.sqlconf/tools/flyway-6.3.1/sql/V2.3.1__schema.sqlconf/tools/flyway-6.3.1/sql/V2.3.2.1__schema.sqlconf/tools/flyway-6.3.1/sql/V2.3.2__schema.sqlconf/tools/flyway-6.3.1/sql/V2.4.0.1__schema.sqlconf/tools/flyway-6.3.1/sql/V2.4.0__schema.sqlconf/tools/flyway-6.3.1/sql/V2.5.0__schema.sqlconf/tools/flyway-6.3.1/sql/V2.5.1__schema.sqlconf/tools/flyway-6.3.1/sql/V2.6.0__schema.sqlconf/tools/flyway-6.3.1/sql/V2.6.1__schema.sqlconf/tools/flyway-6.3.1/sql/V2.6.2__schema.sqlconf/tools/flyway-6.3.1/sql/V3.0.0__schema.sqlconf/tools/flyway-6.3.1/sql/V3.0.1__schema.sqlconf/tools/flyway-6.3.1/sql/V3.1.0__schema.sqlconf/tools/flyway-6.3.1/sql/V3.1.1__schema.sqlconf/tools/flyway-6.3.1/sql/V3.1.2__schema.sqlconf/tools/flyway-6.3.1/sql/V3.10.0.1__schema.sqlconf/tools/flyway-6.3.1/sql/V3.10.0.2__schema.sqlconf/tools/flyway-6.3.1/sql/V3.10.0.5__schema.sqlconf/tools/flyway-6.3.1/sql/V3.10.0__schema.sqlconf/tools/flyway-6.3.1/sql/V3.10.16.2__schema.sqlconf/tools/flyway-6.3.1/sql/V3.10.1__schema.sqlconf/tools/flyway-6.3.1/sql/V3.10.25__schema.sqlconf/tools/flyway-6.3.1/sql/V3.10.2__schema.sqlconf/tools/flyway-6.3.1/sql/V3.10.3__schema.sqlconf/tools/flyway-6.3.1/sql/V3.10.4__schema.sqlconf/tools/flyway-6.3.1/sql/V3.10.5__schema.sqlconf/tools/flyway-6.3.1/sql/V3.10.7__schema.sqlconf/tools/flyway-6.3.1/sql/V3.10.8__schema.sqlconf/tools/flyway-6.3.1/sql/V3.2.0__schema.sqlconf/tools/flyway-6.3.1/sql/V3.2.1__schema.sqlconf/tools/flyway-6.3.1/sql/V3.3.0__schema.sqlconf/tools/flyway-6.3.1/sql/V3.3.1.1__schema.sqlconf/tools/flyway-6.3.1/sql/V3.3.1__schema.sqlconf/tools/flyway-6.3.1/sql/V3.4.0.1__schema.sqlconf/tools/flyway-6.3.1/sql/V3.4.0__schema.sqlconf/tools/flyway-6.3.1/sql/V3.4.1__schema.sqlconf/tools/flyway-6.3.1/sql/V3.4.2__schema.sqlconf/tools/flyway-6.3.1/sql/V3.4.3__schema.sqlconf/tools/flyway-6.3.1/sql/V3.5.0.1__schema.sqlconf/tools/flyway-6.3.1/sql/V3.5.0.2__schema.sqlconf/tools/flyway-6.3.1/sql/V3.5.0__schema.sqlconf/tools/flyway-6.3.1/sql/V3.5.1__schema.sqlconf/tools/flyway-6.3.1/sql/V3.5.2__schema.sqlconf/tools/flyway-6.3.1/sql/V3.5.3__schema.sqlconf/tools/flyway-6.3.1/sql/V3.6.0__schema.sqlconf/tools/flyway-6.3.1/sql/V3.6.1__schema.sqlconf/tools/flyway-6.3.1/sql/V3.7.0.2__schema.sqlconf/tools/flyway-6.3.1/sql/V3.7.0__schema.sqlconf/tools/flyway-6.3.1/sql/V3.7.1__schema.sqlconf/tools/flyway-6.3.1/sql/V3.7.2__schema.sqlconf/tools/flyway-6.3.1/sql/V3.8.0__schema.sqlconf/tools/flyway-6.3.1/sql/V3.8.11.1__schema.sqlconf/tools/flyway-6.3.1/sql/V3.8.14__schema.sqlconf/tools/flyway-6.3.1/sql/V3.8.1__schema.sqlconf/tools/flyway-6.3.1/sql/V3.8.3__schema.sqlconf/tools/flyway-6.3.1/sql/V3.8.4__schema.sqlconf/tools/flyway-6.3.1/sql/V3.8.6__schema.sqlconf/tools/flyway-6.3.1/sql/V3.9.0.1__schema.sqlconf/tools/flyway-6.3.1/sql/V3.9.0.2__schema.sqlconf/tools/flyway-6.3.1/sql/V3.9.0__schema.sqlconf/tools/flyway-6.3.1/sql/V3.9.1__schema.sqlconf/tools/flyway-6.3.1/sql/V4.0.0__schema.sqlconf/tools/flyway-6.3.1/sql/V4.1.0__schema.sqlconf/tools/flyway-6.3.1/sql/V4.1.1__schema.sqlconf/tools/flyway-6.3.1/sql/V4.1.2.1__schema.sqlconf/tools/flyway-6.3.1/sql/V4.1.2__schema.sqlconf/tools/flyway-6.3.1/sql/V4.1.3.1__schema.sqlconf/tools/flyway-6.3.1/sql/V4.1.3__schema.sqlconf/tools/flyway-6.3.1/sql/V4.1.6__schema.sqlconf/tools/flyway-6.3.1/sql/V4.2.0.1__schema.sqlconf/tools/flyway-6.3.1/sql/V4.2.0__schema.sqlconf/tools/flyway-6.3.1/sql/V4.2.2__schema.sqlconf/tools/flyway-6.3.1/sql/V4.3.0__schema.sqlconf/tools/flyway-6.3.1/sql/V4.3.12__schema.sqlconf/tools/flyway-6.3.1/sql/V4.3.18.1__schema.sqlconf/tools/flyway-6.3.1/sql/V4.3.18__schema.sqlconf/tools/flyway-6.3.1/sql/V4.3.24__schema.sqlconf/tools/flyway-6.3.1/sql/V4.3.25__schema.sqlconf/tools/flyway-6.3.1/sql/V4.3.28__schema.sqlconf/tools/flyway-6.3.1/sql/V4.3.35__schema.sqlconf/tools/flyway-6.3.1/sql/V4.3.6.1__schema.sqlconf/tools/flyway-6.3.1/sql/V4.3.6__schema.sqlconf/tools/flyway-6.3.1/sql/V4.3.8.0.10__schema.sqlconf/tools/flyway-6.3.1/sql/V4.3.8.1__schema.sqlconf/tools/flyway-6.3.1/sql/V4.3.8__schema.sqlconf/tools/flyway-6.3.1/sql/V4.3.9__schema.sqlconf/tools/flyway-6.3.1/sql/V4.4.0__schema.sqlconf/tools/flyway-6.3.1/sql/V4.4.24__schema.sqlconf/tools/flyway-6.3.1/sql/V4.4.26__schema.sqlconf/tools/flyway-6.3.1/sql/V4.4.27.1__schema.sqlconf/tools/flyway-6.3.1/sql/V4.4.27__schema.sqlconf/tools/flyway-6.3.1/sql/V4.4.40.2__schema.sqlconf/tools/flyway-6.3.1/sql/V4.4.46__schema.sqlconf/tools/flyway-6.3.1/sql/V4.4.48.1__schema.sqlconf/tools/flyway-6.3.1/sql/V4.4.6__schema.sqlconf/tools/flyway-6.3.1/sql/V4.4.8__schema.sqlconf/tools/flyway-6.3.1/sql/V4.4.9__schema.sqlconf/tools/flyway-6.3.1/sql/V4.5.0__schema.sqlconf/tools/flyway-6.3.1/sql/V4.5.1.1__schema.sqlconf/tools/flyway-6.3.1/sql/V4.5.1.2__schema.sqlconf/tools/flyway-6.3.1/sql/V4.5.11__schema.sqlconf/tools/flyway-6.3.1/sql/V4.5.3__schema.sqlconf/tools/flyway-6.3.1/sql/V4.6.0__schema.sqlconf/tools/flyway-6.3.1/sql/V4.6.11__schema.sqlconf/tools/flyway-6.3.1/sql/V4.6.21.1__schema.sqlconf/tools/flyway-6.3.1/sql/V4.6.21__schema.sqlconf/tools/flyway-6.3.1/sql/V4.6.31__schema.sqlconf/tools/flyway-6.3.1/sql/V4.7.0.1__schema.sqlconf/tools/flyway-6.3.1/sql/V4.7.0.2__schema.sqlconf/tools/flyway-6.3.1/sql/V4.7.0.3__schema.sqlconf/tools/flyway-6.3.1/sql/V4.7.0.4__schema.sqlconf/tools/flyway-6.3.1/sql/V4.7.0__schema.sqlconf/tools/flyway-6.3.1/sql/V4.7.11__schema.sqlconf/tools/flyway-6.3.1/sql/V4.7.13__schema.sqlconf/tools/flyway-6.3.1/sql/V4.7.21__schema.sqlconf/tools/flyway-6.3.1/sql/V4.8.0.2__schema.sqlconf/tools/flyway-6.3.1/sql/V4.8.0.3__schema.sqlconf/tools/flyway-6.3.1/sql/V4.8.0.6__schema.sqlconf/tools/flyway-6.3.1/sql/V4.8.0__schema.sqlconf/tools/flyway-6.3.1/sql/V5.0.0__schema.sqlconf/tools/flyway-6.3.1/sql/V5.1.0__schema.sqlconf/tools/flyway-6.3.1/sql/V5.1.19__schema.sqlconf/tools/flyway-6.3.1/sql/V5.1.20__schema.sqlconf/tools/flyway-6.3.1/sql/V5.1.4__schema.sqlconf/tools/flyway-6.3.1/sql/V5.1.8.1__schema.sqlconf/tools/flyway-6.3.1/sql/V5.1.8__schema.sqlconf/tools/flyway-6.3.1/sql/V5.2.0__schema.sqlconf/tools/flyway-6.3.1/sql/V5.2.1__schema.sqlconf/tools/flyway-6.3.1/sql/V5.3.0__schema.sqlconf/tools/flyway-6.3.1/sql/V5.3.20__schema.sqlconf/tools/flyway-6.3.1/sql/V5.3.22__schema.sqlconf/tools/flyway-6.3.1/sql/V5.3.28__schema.sqlconf/tools/flyway-6.3.1/sql/V5.3.36__schema.sqlconf/tools/flyway-6.3.1/sql/V5.3.40__schema.sqlconf/tools/flyway-6.3.1/sql/V5.3.46__schema.sqlconf/tools/flyway-6.3.1/sql/V5.3.52__schema.sqlconf/tools/flyway-6.3.1/sql/V5.3.6__schema.sqlconf/tools/flyway-6.3.1/sql/V5.4.0__schema.sqlconf/tools/flyway-6.3.1/sql/V5.4.2__schema.sqlconf/tools/flyway-6.3.1/sql/V5.4.6__schema.sqlconf/tools/flyway-6.3.1/sql/V5.5.0__schema.sqlconf/tools/flyway-6.3.1/sql/V5.5.6__schema.sqlconf/tools/flyway-6.3.1/sql/beforeMigrate.sqlconfiguration/src/main/java/org/zstack/configuration/ConfigurationManagerImpl.javaconfiguration/src/main/java/org/zstack/configuration/DiskOfferingCascadeExtension.javaconfiguration/src/main/java/org/zstack/configuration/InstanceOfferingCascadeExtension.javaconfiguration/src/main/java/org/zstack/configuration/SqlForeignKeyGenerator.javaconfiguration/src/main/java/org/zstack/configuration/SqlIndexGenerator.javaconfiguration/src/main/java/org/zstack/configuration/TestLinkDocumentGenerator.javaconfiguration/src/main/java/org/zstack/configuration/testlink/schema/ObjectFactory.javaconfiguration/src/main/java/org/zstack/configuration/testlink/schema/RequirementCategory.javaconfiguration/src/main/java/org/zstack/configuration/testlink/schema/RequirementSpecification.javaconfiguration/src/main/java/org/zstack/configuration/testlink/schema/package-info.javaconsole/src/main/java/org/zstack/console/AbstractConsoleProxyBackend.javaconsole/src/main/java/org/zstack/console/ConsoleManagerImpl.javacore/src/main/java/org/zstack/core/Platform.javacore/src/main/java/org/zstack/core/aspect/EncryptColumnAspect.ajcore/src/main/java/org/zstack/core/captcha/APIRefreshCaptchaMsg.javacore/src/main/java/org/zstack/core/captcha/CaptchaImpl.javacore/src/main/java/org/zstack/core/checkpoint/CheckPointEntryVO.javacore/src/main/java/org/zstack/core/checkpoint/CheckPointEntryVO_.javacore/src/main/java/org/zstack/core/checkpoint/CheckPointVO.javacore/src/main/java/org/zstack/core/checkpoint/CheckPointVO_.javacore/src/main/java/org/zstack/core/cloudbus/CloudBus.javacore/src/main/java/org/zstack/core/cloudbus/CloudBusController.javacore/src/main/java/org/zstack/core/cloudbus/CloudBusImpl3.javacore/src/main/java/org/zstack/core/config/APIGetGlobalConfigOptionsMsg.javacore/src/main/java/org/zstack/core/config/APIGetGuestOsMetadataMsg.javacore/src/main/java/org/zstack/core/config/APIQueryGlobalConfigMsg.javacore/src/main/java/org/zstack/core/config/APIRefreshGuestOsMetadataMsg.javacore/src/main/java/org/zstack/core/config/APIResetGlobalConfigMsg.javacore/src/main/java/org/zstack/core/config/APIUpdateGlobalConfigMsg.javacore/src/main/java/org/zstack/core/config/GlobalConfigFacadeImpl.javacore/src/main/java/org/zstack/core/config/GlobalConfigVO.javacore/src/main/java/org/zstack/core/config/GlobalConfigVO_.javacore/src/main/java/org/zstack/core/config/GuestOsHelper.javacore/src/main/java/org/zstack/core/config/package-info.javacore/src/main/java/org/zstack/core/config/schema/GlobalConfig.javacore/src/main/java/org/zstack/core/config/schema/GuestOsCategory.javacore/src/main/java/org/zstack/core/config/schema/GuestOsCharacter.javacore/src/main/java/org/zstack/core/config/schema/ObjectFactory.javacore/src/main/java/org/zstack/core/config/schema/package-info.javacore/src/main/java/org/zstack/core/convert/PasswordConverter.javacore/src/main/java/org/zstack/core/convert/SpecialDataConverter.javacore/src/main/java/org/zstack/core/db/C3p0ConnectionTester.javacore/src/main/java/org/zstack/core/db/DatabaseFacade.javacore/src/main/java/org/zstack/core/db/DatabaseFacadeImpl.javacore/src/main/java/org/zstack/core/db/DbEntityListerImpl.javacore/src/main/java/org/zstack/core/db/EntityListener.javacore/src/main/java/org/zstack/core/db/EntityMetadata.javacore/src/main/java/org/zstack/core/db/Q.javacore/src/main/java/org/zstack/core/db/QueryMore.javacore/src/main/java/org/zstack/core/db/SQL.javacore/src/main/java/org/zstack/core/db/SimpleQuery.javacore/src/main/java/org/zstack/core/db/SimpleQueryImpl.javacore/src/main/java/org/zstack/core/db/TransactionIsolationLevelSetter.javacore/src/main/java/org/zstack/core/db/UpdateQuery.javacore/src/main/java/org/zstack/core/db/UpdateQueryImpl.javacore/src/main/java/org/zstack/core/db/hibernate/InlineIdsIdsOrClauseDeleteHandlerImpl2.javacore/src/main/java/org/zstack/core/db/hibernate/InlineIdsOrClauseBulkIdStrategy2.javacore/src/main/java/org/zstack/core/db/hibernate/InlineIdsOrClauseUpdateHandlerImpl2.javacore/src/main/java/org/zstack/core/debug/APICleanQueueMsg.javacore/src/main/java/org/zstack/core/debug/APIDebugSignalMsg.javacore/src/main/java/org/zstack/core/debug/APIGetDebugSignalMsg.javacore/src/main/java/org/zstack/core/encrypt/EncryptFacadeImpl.javacore/src/main/java/org/zstack/core/encrypt/EncryptManagerImpl.javacore/src/main/java/org/zstack/core/errorcode/APICheckElaborationContentMsg.javacore/src/main/java/org/zstack/core/errorcode/APIGetElaborationCategoriesMsg.javacore/src/main/java/org/zstack/core/errorcode/APIGetElaborationsMsg.javacore/src/main/java/org/zstack/core/errorcode/APIReloadElaborationMsg.javacore/src/main/java/org/zstack/core/errorcode/ErrorFacadeImpl.javacore/src/main/java/org/zstack/core/errorcode/schema/Error.javacore/src/main/java/org/zstack/core/errorcode/schema/ObjectFactory.javacore/src/main/java/org/zstack/core/errorcode/schema/package-info.javacore/src/main/java/org/zstack/core/eventlog/APIQueryEventLogMsg.javacore/src/main/java/org/zstack/core/eventlog/EventLogManager.java
| IF (NEW.`allocateResourceUuid` = NULL) THEN | ||
| update `EcsInstanceVO` set `ecsEipUuid`=NULL | ||
| where `ecsEipUuid`=OLD.`uuid` | ||
| and OLD.`eipType`='aliyun' | ||
| and OLD.`allocateResourceType`='EcsInstanceVO'; |
There was a problem hiding this comment.
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.
| 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, |
There was a problem hiding this comment.
🧩 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.sqlRepository: 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 1Repository: 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.sqlRepository: 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.sqlRepository: 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 -40Repository: MatheMatrix/zstack
Length of output: 544
🏁 Script executed:
# 检查是否有其他表中的 vmInstanceUuid 列定义,看看是否存在一致的模式
rg -n 'vmInstanceUuid.*varchar' conf/tools/flyway-6.3.1/sql/V1.9__schema.sqlRepository: 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.sqlRepository: 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.
| `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; |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, find the SQL file
find . -name "V2.1.0__schema.sql" -type fRepository: 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 -20Repository: 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"
fiRepository: 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"
fiRepository: 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"
fiRepository: 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.
| 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; |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
find . -name "V2.1.0__schema.sql" -type fRepository: MatheMatrix/zstack
Length of output: 147
🏁 Script executed:
wc -l ./conf/tools/flyway-6.3.1/sql/V2.1.0__schema.sqlRepository: MatheMatrix/zstack
Length of output: 114
🏁 Script executed:
sed -n '450,480p' ./conf/tools/flyway-6.3.1/sql/V2.1.0__schema.sqlRepository: MatheMatrix/zstack
Length of output: 1752
🏁 Script executed:
sed -n '462,468p' ./conf/tools/flyway-6.3.1/sql/V2.1.0__schema.sqlRepository: 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.
| 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.
| 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'); | ||
|
|
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, let's locate and read the SQL file
find . -name "V2.2.0__schema.sql" -type fRepository: 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 -150Repository: 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 15Repository: MatheMatrix/zstack
Length of output: 2498
🏁 Script executed:
# Search for L3NetworkEO table definition
rg "CREATE TABLE.*L3NetworkEO" -A 15Repository: 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 行引用了未定义的变量
name和data,应为函数参数policy_name和policy_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.
| 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`; |
There was a problem hiding this comment.
存储过程中存在严重的游标变量顺序错误
MdevDeviceAddVendor 存储过程存在两个关键问题:
-
游标变量赋值顺序错误:Line 160 的
SELECT pci.uuid, pci.vendor返回的是uuid在前、vendor在后,但 Line 165 的FETCH cur INTO vendor, pciDeviceUuid却将uuid赋给了vendor变量,将vendor赋给了pciDeviceUuid变量。 -
变量名与列名冲突: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.
| 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; |
There was a problem hiding this comment.
这个表替换过程在失败重试时不可恢复。
DROP TABLE / RENAME TABLE 都会隐式 COMMIT,START 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/替换步骤以保证脚本可重入和幂等。
| 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; |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
find . -name "V5.3.22__schema.sql" -type fRepository: MatheMatrix/zstack
Length of output: 149
🏁 Script executed:
cat conf/tools/flyway-6.3.1/sql/V5.3.22__schema.sql | head -100Repository: MatheMatrix/zstack
Length of output: 1561
🏁 Script executed:
wc -l conf/tools/flyway-6.3.1/sql/V5.3.22__schema.sqlRepository: MatheMatrix/zstack
Length of output: 112
内层 SELECT ... INTO 会误触发游标结束条件,导致数据迁移不完整。
同一个 NOT FOUND handler 覆盖了 FETCH 和内层 SELECT ... INTO 操作。当某个 group 没有匹配的 instance 时,内层查询返回零行触发 NOT FOUND,handler 将 done 置为 TRUE。下一个循环迭代立即检测到 done=TRUE 后 LEAVE 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.
| DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; | ||
|
|
There was a problem hiding this comment.
🧩 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.sqlRepository: MatheMatrix/zstack
Length of output: 273
🏁 Script executed:
cat -n conf/tools/flyway-6.3.1/sql/V5.3.40__schema.sql | head -250Repository: 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 -20Repository: 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行的 createDate 和 lastOpDate 字段使用了非法的默认值。改为 DEFAULT CURRENT_TIMESTAMP。
表名和列名必须使用反引号包裹
第52、69、78、106等多处缺少反引号,例如:
FROM ModelServiceImageVO→FROM \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.
| 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; |
There was a problem hiding this comment.
🧩 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 -20Repository: 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 -250Repository: MatheMatrix/zstack
Length of output: 10242
🏁 Script executed:
tail -50 conf/tools/flyway-6.3.1/sql/V5.4.6__schema.sqlRepository: MatheMatrix/zstack
Length of output: 2143
🏁 Script executed:
wc -l conf/tools/flyway-6.3.1/sql/V5.4.6__schema.sqlRepository: 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.sqlRepository: MatheMatrix/zstack
Length of output: 226
🏁 Script executed:
grep -n "DROP PROCEDURE" conf/tools/flyway-6.3.1/sql/V5.4.6__schema.sqlRepository: 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),与其他迁移过程(如 fixUsedIpGatewayAndNetmask、updateModelServiceFramework 等)不一致,建议在调用后添加清理。
表名和列名也应使用反引号包裹,避免 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.
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>
Summary
Test Results
assert false)Atomic Commits (13)
Related
modernize/full-stack-5512@@2on zstackio/premiumsync from gitlab !9293