fix(audit): resolve 8-hour timezone offset in audit log timestamps#472
Open
dongmucat wants to merge 1 commit into
Open
fix(audit): resolve 8-hour timezone offset in audit log timestamps#472dongmucat wants to merge 1 commit into
dongmucat wants to merge 1 commit into
Conversation
audit_log.created_at was TIMESTAMP (without timezone). The JDBC read path used rs.getTimestamp() which interprets values using the JVM default timezone, causing an 8-hour offset when JVM TZ != UTC. Fix: upgrade column to TIMESTAMPTZ (V42 migration) and switch the read path to OffsetDateTime which is timezone-independent for both column types.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
修复管理员"系统操作记录"页面时间列显示比实际时间晚 8 小时的 bug。根因是
audit_log.created_at为TIMESTAMP(无时区),读出路径rs.getTimestamp()使用 JVM 默认时区解释裸值,当 JVM TZ != UTC 时产生偏移。变更内容
后端实现
audit_log.created_at从TIMESTAMP升级为TIMESTAMPTZ,历史数据通过USING created_at AT TIME ZONE 'UTC'锚定为 UTC(与 V18/V19/V23/V25 同模式)AdminAuditLogAppService.java将rs.getTimestamp("created_at")替换为rs.getObject(col, OffsetDateTime.class).toInstant(),对 TIMESTAMP 和 TIMESTAMPTZ 列均正确,不依赖 JVM 时区前端实现
parseServerDateTime对带Z的字符串处理已正确)测试覆盖
AdminAuditLogAppServiceTest.rowMapper_readsCreatedAtAsUtcInstant— 通过 ArgumentCaptor 抓取 RowMapper,mock ResultSet 验证 OffsetDateTime 读取路径,并断言不再调用getTimestamp()质量门禁
make test-backend-app通过(471 tests, 0 failures)make generate-api不需要安全考虑
本次变更不涉及安全敏感内容。仅修复时间展示精度问题。
相关文档
docs/15-backend-time-governance-plan.md3.1 节:系统事件时间统一为 TIMESTAMPTZ测试说明
本地验证步骤
make dev-all启动本地环境(Flyway 自动执行 V42)docker exec <postgres> psql -U skillhub -c "SELECT pg_typeof(created_at) FROM audit_log LIMIT 1;"确认列类型为timestamp with time zone回归测试范围
部署注意
ALTER COLUMN ... TYPE TIMESTAMPTZ会取 ACCESS EXCLUSIVE 锁并重写整表,建议在低峰期执行