Skip to content

<fix>[mevoco]: save license snapshot in LicenseAuthorizedCapacityVO#4310

Open
zstack-robot-2 wants to merge 1 commit into
feature-zsv-5.1.0-license-clientfrom
sync/wenhao.zhang/zsv-ldap-5@@2
Open

<fix>[mevoco]: save license snapshot in LicenseAuthorizedCapacityVO#4310
zstack-robot-2 wants to merge 1 commit into
feature-zsv-5.1.0-license-clientfrom
sync/wenhao.zhang/zsv-ldap-5@@2

Conversation

@zstack-robot-2

Copy link
Copy Markdown
Collaborator

Resolves: ZSV-12506
Related: ZSV-12274

Change-Id: I6c62666a64656965736e6c6279786b61676f7463

sync from gitlab !10270

Resolves: ZSV-12506
Related: ZSV-12274

Change-Id: I6c62666a64656965736e6c6279786b61676f7463
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

数据库迁移脚本 V5.1.0__schema.sql 重构了 LicenseAuthorizedCapacityVO 表,移除 resourceUuidresourceInfotype 字段,新增 prodInfostateissueTimeexpireTimelocalUsedotherUsed 字段。SDK 类 LicenseAuthorizedCapacityInventory 同步替换了对应的公开字段与访问器。

Changes

LicenseAuthorizedCapacity 字段重构

Layer / File(s) Summary
数据库迁移:表结构字段替换
conf/db/zsv/V5.1.0__schema.sql
扩展功能注释范围(新增 ZSV-12506),并在 LicenseAuthorizedCapacityVO 中移除 resourceUuid/resourceInfo/type 三列,新增 prodInfostateissueTimeexpireTimelocalUsedotherUsed 列,quota 约束调整为 NOT NULL DEFAULT 0
SDK 库存类:公开字段与访问器替换
sdk/src/main/java/org/zstack/sdk/license/entity/server/LicenseAuthorizedCapacityInventory.java
移除 resourceUuid/resourceInfo/type 字段及其 getter/setter,新增 prodInfo(String)、state(String)、issueTime/expireTime(Timestamp)、localUsed/otherUsed(Long)及对应访问器,与数据库结构对齐。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 旧字段悄悄退场,
新列定义闪亮登场,
prodInfo 与 state 并肩,
issueTime 计时不慌,
localUsed 与 otherUsed 相望,
兔子跳过迁移脚本,
数据库焕然一新模样!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed PR标题准确反映了主要变更,即在LicenseAuthorizedCapacityVO中保存许可证快照数据,与数据库架构调整和实体类字段更新的核心意图相符。
Description check ✅ Passed PR描述提供了问题号(ZSV-12506)、关联问题(ZSV-12274)和变更ID,与实际的许可证授权容量功能更新相关。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sync/wenhao.zhang/zsv-ldap-5@@2

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

@MatheMatrix

Copy link
Copy Markdown
Owner

Comment from wenhao.zhang:

本提交仍然在开发的第一个版本,没有兼容老版本这个说法,所以 create table 修改破坏兼容这种事情就别在 review 提出来了

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against 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

📥 Commits

Reviewing files that changed from the base of the PR and between 04b0460 and e176141.

📒 Files selected for processing (2)
  • conf/db/zsv/V5.1.0__schema.sql
  • sdk/src/main/java/org/zstack/sdk/license/entity/server/LicenseAuthorizedCapacityInventory.java

Comment on lines 134 to +145
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,

Copy link
Copy Markdown

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

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