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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions conf/db/zsv/V5.1.0__schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ CALL CREATE_INDEX('AccountVO', 'idxAccountVOname', 'name');
CALL DELETE_INDEX('AccountVO', 'name');
ALTER TABLE `zstack`.`AccountVO` ADD CONSTRAINT `uqAccountVOSourceName` UNIQUE (`source`, `name`);

-- Feature: ZCenter License & License Client | ZSV-12274
-- Feature: ZCenter License & License Client | ZSV-12274, ZSV-12506

CREATE TABLE IF NOT EXISTS `zstack`.`LicenseAuthorizedNodeVO` (
`uuid` char(32) NOT NULL UNIQUE,
Expand All @@ -134,12 +134,15 @@ CREATE TABLE IF NOT EXISTS `zstack`.`LicenseAuthorizedNodeVO` (
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,
Comment on lines 134 to +145

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

`lastOpDate` timestamp NOT NULL DEFAULT '1999-12-31 23:59:59' ON UPDATE CURRENT_TIMESTAMP,
`createDate` timestamp NOT NULL DEFAULT '1999-12-31 23:59:59',
PRIMARY KEY (`id`),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,12 @@ public java.lang.String getNodeUuid() {
return this.nodeUuid;
}

public java.lang.String resourceUuid;
public void setResourceUuid(java.lang.String resourceUuid) {
this.resourceUuid = resourceUuid;
public java.lang.String prodInfo;
public void setProdInfo(java.lang.String prodInfo) {
this.prodInfo = prodInfo;
}
public java.lang.String getResourceUuid() {
return this.resourceUuid;
}

public java.lang.String resourceInfo;
public void setResourceInfo(java.lang.String resourceInfo) {
this.resourceInfo = resourceInfo;
}
public java.lang.String getResourceInfo() {
return this.resourceInfo;
public java.lang.String getProdInfo() {
return this.prodInfo;
}

public java.lang.String quotaType;
Expand All @@ -60,12 +52,44 @@ public java.lang.String getLicenseType() {
return this.licenseType;
}

public java.lang.String type;
public void setType(java.lang.String type) {
this.type = type;
public java.lang.String state;
public void setState(java.lang.String state) {
this.state = state;
}
public java.lang.String getState() {
return this.state;
}

public java.sql.Timestamp issueTime;
public void setIssueTime(java.sql.Timestamp issueTime) {
this.issueTime = issueTime;
}
public java.sql.Timestamp getIssueTime() {
return this.issueTime;
}

public java.sql.Timestamp expireTime;
public void setExpireTime(java.sql.Timestamp expireTime) {
this.expireTime = expireTime;
}
public java.sql.Timestamp getExpireTime() {
return this.expireTime;
}

public java.lang.Long localUsed;
public void setLocalUsed(java.lang.Long localUsed) {
this.localUsed = localUsed;
}
public java.lang.Long getLocalUsed() {
return this.localUsed;
}

public java.lang.Long otherUsed;
public void setOtherUsed(java.lang.Long otherUsed) {
this.otherUsed = otherUsed;
}
public java.lang.String getType() {
return this.type;
public java.lang.Long getOtherUsed() {
return this.otherUsed;
}

public java.sql.Timestamp createDate;
Expand Down