Skip to content

<fix>[vpc-dns]: ZSTAC-85599 fix dns record upgrade sql#4124

Closed
zstack-robot-2 wants to merge 1 commit into
5.4.7-nexavmfrom
sync/hongbo.liu/hongbo.liu-ZSTAC-85599
Closed

<fix>[vpc-dns]: ZSTAC-85599 fix dns record upgrade sql#4124
zstack-robot-2 wants to merge 1 commit into
5.4.7-nexavmfrom
sync/hongbo.liu/hongbo.liu-ZSTAC-85599

Conversation

@zstack-robot-2
Copy link
Copy Markdown
Collaborator

Summary

Move VPC DNS record schema from already-used V5.4.7 migration to new V5.4.7.1 migration so v30 to v40 upgrade executes it.

Changes

  • Keep V5.4.7__schema.sql empty for checksum compatibility.
  • Add V5.4.7.1__schema.sql with VpcRouterDnsRecordVO DDL.

Testing

  • git diff --check
  • SQL-only change reviewed
  • CI pipeline

Resolves: ZSTAC-85599

sync from gitlab !10023

Move DNS record schema to a new 5.4.7.1 migration.

Keep V5.4.7 schema compatible with the v37 empty migration.

Resolves: ZSTAC-85599

Change-Id: I44fd258a1d9876aabbe50a23b71958c070629ce0
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 27, 2026

Review Change Stack

总览

本次变更在数据库升级脚本中新增 VpcRouterDnsRecordVO 表的定义,该表用于存储 VPC 路由器和 HA 组的 DNS 记录,并从现有迁移脚本中移除该表的原始定义,实现脚本版本的重组织。

变更内容

VpcRouterDnsRecordVO 表迁移

层 / 文件 说明
DNS 记录表结构定义
conf/db/upgrade/V5.4.7.1__schema.sql, conf/db/upgrade/V5.4.7__schema.sql
新增表 VpcRouterDnsRecordVO,包含自增 id、唯一 uuid、DNS 记录字段(type 默认值为 'A'、domain、ip)、时间戳(createDate、lastOpDate 带自动更新)、主键与唯一约束、复合查询索引及级联删除外键(关联 vpcRouterUuid 和 vpcHaGroupUuid)。原定义从 V5.4.7__schema.sql 移至 V5.4.7.1__schema.sql。

预估代码审查工作量

🎯 2 (简单) | ⏱️ ~10 分钟

诗歌

🐰 数据库表在迁移,
DNS 记录守护着路由器的秘密,
外键约束优雅而级联,
VPC 从此记录完整!✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed PR标题遵循了规定的[scope]: 格式,长度54字符未超过72字符限制,准确概括了主要变更内容。
Description check ✅ Passed PR描述清晰地说明了变更的目的、具体改动和测试情况,与代码变更内容完全相关且信息充分。
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sync/hongbo.liu/hongbo.liu-ZSTAC-85599

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

Copy link
Copy Markdown

@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: 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/upgrade/V5.4.7.1__schema.sql`:
- Around line 9-10: 将两个 TIMESTAMP 字段的非法默认值替换为项目哨兵值:把 createDate 和 lastOpDate 当前的
DEFAULT '0000-00-00 00:00:00' 改为 DEFAULT '2000-01-01 00:00:00'(保持 NOT NULL),并保留
lastOpDate 的 ON UPDATE CURRENT_TIMESTAMP;不要将 createDate 设为 DEFAULT
CURRENT_TIMESTAMP,以避免在存在 ON UPDATE CURRENT_TIMESTAMP 的列时触发 MySQL Error
1293,真实创建时间由 ModelServiceRefVO.PrePersist 在 Java 层填充。
🪄 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: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)

Review profile: CHILL

Plan: Pro

Run ID: 517476e5-5902-4d4e-b379-18485e7e9fa0

📥 Commits

Reviewing files that changed from the base of the PR and between be26ff1 and 5641744.

📒 Files selected for processing (2)
  • conf/db/upgrade/V5.4.7.1__schema.sql
  • conf/db/upgrade/V5.4.7__schema.sql
💤 Files with no reviewable changes (1)
  • conf/db/upgrade/V5.4.7__schema.sql

Comment on lines +9 to +10
`createDate` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
`lastOpDate` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
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 | ⚡ Quick win

时间戳字段必须使用正确的默认值

这两个时间戳字段使用了 DEFAULT '0000-00-00 00:00:00',这违反了编码规范。根据项目历史经验,在 MySQL 5.7 环境中(explicit_defaults_for_timestamp=OFF),当表中已有一个带 ON UPDATE CURRENT_TIMESTAMP 的 TIMESTAMP 列(如 lastOpDate)时,第二个 TIMESTAMP 列(如 createDate)不能使用 DEFAULT CURRENT_TIMESTAMP,否则会触发 MySQL Error 1293。

应使用哨兵默认值 '2000-01-01 00:00:00' 代替 '0000-00-00 00:00:00',Java 层的 PrePersist 回调会在插入新记录时设置真实的创建时间戳。

🔧 建议的修复方案
-    `createDate` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
-    `lastOpDate` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
+    `createDate` TIMESTAMP NOT NULL DEFAULT '2000-01-01 00:00:00',
+    `lastOpDate` TIMESTAMP NOT NULL DEFAULT '2000-01-01 00:00:00' ON UPDATE CURRENT_TIMESTAMP,

Based on learnings: In ZStack MySQL upgrade scripts under conf/db/upgrade/*.sql, if a table already contains a TIMESTAMP column defined with ON UPDATE CURRENT_TIMESTAMP (e.g., lastOpDate), then any second TIMESTAMP column (e.g., createDate) must NOT use DEFAULT CURRENT_TIMESTAMP. This repository's CI/validated environment uses MySQL 5.7 with explicit_defaults_for_timestamp=OFF, which can trigger MySQL Error 1293 (only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT/ON UPDATE). Use a non-CURRENT_TIMESTAMP sentinel default such as '2000-01-01 00:00:00' (and typically keep it NOT NULL), and rely on ModelServiceRefVO.PrePersist in Java to set the real creation timestamp for new JPA-managed rows.

📝 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
`createDate` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
`lastOpDate` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
`createDate` TIMESTAMP NOT NULL DEFAULT '2000-01-01 00:00:00',
`lastOpDate` TIMESTAMP NOT NULL DEFAULT '2000-01-01 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
🤖 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/upgrade/V5.4.7.1__schema.sql` around lines 9 - 10, 将两个 TIMESTAMP
字段的非法默认值替换为项目哨兵值:把 createDate 和 lastOpDate 当前的 DEFAULT '0000-00-00 00:00:00' 改为
DEFAULT '2000-01-01 00:00:00'(保持 NOT NULL),并保留 lastOpDate 的 ON UPDATE
CURRENT_TIMESTAMP;不要将 createDate 设为 DEFAULT CURRENT_TIMESTAMP,以避免在存在 ON UPDATE
CURRENT_TIMESTAMP 的列时触发 MySQL Error 1293,真实创建时间由 ModelServiceRefVO.PrePersist 在
Java 层填充。

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.

1 participant