<fix>[vpc-dns]: ZSTAC-85599 fix dns record upgrade sql#4124
<fix>[vpc-dns]: ZSTAC-85599 fix dns record upgrade sql#4124zstack-robot-2 wants to merge 1 commit into
Conversation
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
总览本次变更在数据库升级脚本中新增 VpcRouterDnsRecordVO 表的定义,该表用于存储 VPC 路由器和 HA 组的 DNS 记录,并从现有迁移脚本中移除该表的原始定义,实现脚本版本的重组织。 变更内容VpcRouterDnsRecordVO 表迁移
预估代码审查工作量🎯 2 (简单) | ⏱️ ~10 分钟 诗歌
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
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/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
📒 Files selected for processing (2)
conf/db/upgrade/V5.4.7.1__schema.sqlconf/db/upgrade/V5.4.7__schema.sql
💤 Files with no reviewable changes (1)
- conf/db/upgrade/V5.4.7__schema.sql
| `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, |
There was a problem hiding this comment.
时间戳字段必须使用正确的默认值
这两个时间戳字段使用了 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.
| `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 层填充。
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
Testing
Resolves: ZSTAC-85599
sync from gitlab !10023