<fix>[mevoco]: save license snapshot in LicenseAuthorizedCapacityVO#4310
<fix>[mevoco]: save license snapshot in LicenseAuthorizedCapacityVO#4310zstack-robot-2 wants to merge 1 commit into
Conversation
Resolves: ZSV-12506 Related: ZSV-12274 Change-Id: I6c62666a64656965736e6c6279786b61676f7463
Walkthrough数据库迁移脚本 ChangesLicenseAuthorizedCapacity 字段重构
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
Comment from wenhao.zhang: 本提交仍然在开发的第一个版本,没有兼容老版本这个说法,所以 create table 修改破坏兼容这种事情就别在 review 提出来了 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@conf/db/zsv/V5.1.0__schema.sql`:
- Around line 134-145: The CREATE TABLE IF NOT EXISTS statement for the
LicenseAuthorizedCapacityVO table only applies to new installations and will not
modify existing tables during upgrades, causing the new NOT NULL columns to be
missing from databases being upgraded. Create a corresponding upgrade migration
script in the conf/db/upgrade/ directory that uses ALTER TABLE statements to add
each of the missing columns (nodeUuid, prodInfo, quotaType, quota, licenseType,
state, issueTime, expireTime, localUsed, otherUsed) to the existing
LicenseAuthorizedCapacityVO table with appropriate default values, and follow
with UPDATE statements to backfill these columns for existing historical records
to maintain data integrity and consistency with the application layer contract.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 9cc40388-9209-4514-b382-01c392479d26
📒 Files selected for processing (2)
conf/db/zsv/V5.1.0__schema.sqlsdk/src/main/java/org/zstack/sdk/license/entity/server/LicenseAuthorizedCapacityInventory.java
| CREATE TABLE IF NOT EXISTS `zstack`.`LicenseAuthorizedCapacityVO` ( | ||
| `id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT, | ||
| `nodeUuid` char(32) NOT NULL, | ||
| `resourceUuid` char(32) DEFAULT NULL, | ||
| `resourceInfo` text DEFAULT NULL, | ||
| `prodInfo` varchar(255) NOT NULL, | ||
| `quotaType` varchar(64) NOT NULL, | ||
| `quota` bigint unsigned DEFAULT 0, | ||
| `quota` bigint unsigned NOT NULL DEFAULT 0, | ||
| `licenseType` varchar(64) NOT NULL, | ||
| `type` varchar(64) NOT NULL, | ||
| `state` varchar(64) NOT NULL DEFAULT 'active', | ||
| `issueTime` timestamp NOT NULL DEFAULT '1999-12-31 23:59:59', | ||
| `expireTime` timestamp NOT NULL DEFAULT '1999-12-31 23:59:59', | ||
| `localUsed` bigint unsigned NOT NULL DEFAULT 0, | ||
| `otherUsed` bigint unsigned NOT NULL DEFAULT 0, |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# 1) 查看该表相关 SQL 变更位置
rg -n --iglob '*.sql' -C2 'LicenseAuthorizedCapacityVO'
# 2) 检查是否存在升级 ALTER(新增新列/删除旧列)
rg -n --iglob '*.sql' -C2 'ALTER TABLE.*LicenseAuthorizedCapacityVO|ADD COLUMN.*(prodInfo|state|issueTime|expireTime|localUsed|otherUsed)|DROP COLUMN.*(resourceUuid|resourceInfo|type)'
# 3) 检查是否存在历史数据处理步骤(过程/函数/回填)
rg -n --iglob '*.sql' -C2 'PROCEDURE|FUNCTION|UPDATE\s+`?zstack`?\.`?LicenseAuthorizedCapacityVO`?'Repository: MatheMatrix/zstack
Length of output: 50374
缺少 LicenseAuthorizedCapacityVO 表的升级迁移与历史数据处理逻辑。
第134行的 CREATE TABLE IF NOT EXISTS 仅用于全新安装;升级场景下旧表已存在时,此语句无法应用新字段定义。第137-145行引入的多个 NOT NULL 列缺乏相应的 ALTER TABLE、数据回填或存储过程支持,会导致数据库结构与应用层字段契约不一致。
建议补充升级脚本,在对应的 conf/db/upgrade/ 版本文件中添加:
ALTER TABLE新增缺失的列(带合理默认值)UPDATE语句进行历史数据回填- 可选:
DROP COLUMN删除废弃的旧列
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@conf/db/zsv/V5.1.0__schema.sql` around lines 134 - 145, The CREATE TABLE IF
NOT EXISTS statement for the LicenseAuthorizedCapacityVO table only applies to
new installations and will not modify existing tables during upgrades, causing
the new NOT NULL columns to be missing from databases being upgraded. Create a
corresponding upgrade migration script in the conf/db/upgrade/ directory that
uses ALTER TABLE statements to add each of the missing columns (nodeUuid,
prodInfo, quotaType, quota, licenseType, state, issueTime, expireTime,
localUsed, otherUsed) to the existing LicenseAuthorizedCapacityVO table with
appropriate default values, and follow with UPDATE statements to backfill these
columns for existing historical records to maintain data integrity and
consistency with the application layer contract.
Source: Coding guidelines
Resolves: ZSV-12506
Related: ZSV-12274
Change-Id: I6c62666a64656965736e6c6279786b61676f7463
sync from gitlab !10270