fix(migration): fail fast on critical schema gaps#1326
Open
wolfkill wants to merge 1 commit into
Open
Conversation
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.
背景
修复 #1319。
Fixes #1319.
当前启动流程里,
RunMigrationsWithOptions失败后只打印 warning 并继续启动。如果 000041 迁移因为pg_trgm/ trigram index / dirty migration 等问题失败,Wiki 入库、任务队列和知识图谱相关功能可能在缺少关键 schema 的情况下继续运行,表现为前端无感知卡住或后台任务静默失败。修改内容
schema_migrations.dirty=true,直接拒绝启动并给出修复指引。wiki_pages、wiki_log_entries、task_pending_ops、task_dead_letters。pg_trgm修复提示,便于定位 000041 trigram index 失败。验证
CGO_LDFLAGS='-lc++' go test ./internal/container -run 'TestValidateCriticalSchemaAfterMigrationFailure' -count=1CGO_LDFLAGS='-lc++' go test ./internal/database ./internal/container -count=1CGO_LDFLAGS='-lc++' go test ./internal/application/repository ./internal/application/service -run '^$' -count=1git diff --cached --checkschema_migrations为42|false,且wiki_pages、wiki_log_entries、task_pending_ops、task_dead_letters均存在。GET /health,返回{"status":"ok"};日志显示迁移版本 42、dirty=false、服务成功监听0.0.0.0:8080。