数据库迁移审查与清理
db-migration-review
在运行 make migrate-create 后审查并清理自动生成的数据库迁移文件。识别并移除无关的 Atlas schema 漂移,例如删除部分索引、无操作的索引重建,以及与预期迁移无关的其他操作。适用于创建数据库迁移、运行 make migrate-create 或审查 .up.sql 文件时。
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-14
- Stars
- ★ 10
- Forks
- 8
01 前言 Front Matter
- name
- db-migration-review
- description
- Review and clean up auto-generated database migration files after running make migrate-create. Identifies and removes unrelated Atlas schema drift such as dropped partial indexes, no-op index recreations, and other operations not related to the intended migration. Use when creating database migrations, running make migrate-create, or reviewing .up.sql files.
03 SKILL.md 正文
DB Migration Review
Atlas diffs the Ent schema against a dev database and often emits operations unrelated to the change, because it can't model some indexes. Review every generated .up.sql in pkg/database/migrations/ before it is committed.
Indexes Atlas can't model (never drop)
| Index | Table | Created in |
|---|---|---|
agentexecution_stage_id_agent_index_top_level |
agent_executions |
20260225235224_add_orchestrator_sub_agent_fields.up.sql |
agentexecution_parent_execution_id_agent_index_sub_agent |
agent_executions |
20260225235224_add_orchestrator_sub_agent_fields.up.sql |
idx_alert_sessions_alert_data_gin |
alert_sessions |
CreateGINIndexes in pkg/database/migrations.go |
idx_alert_sessions_final_analysis_gin |
alert_sessions |
CreateGINIndexes in pkg/database/migrations.go |
idx_timeline_events_content_gin |
timeline_events |
CreateGINIndexes in pkg/database/migrations.go |
idx_alert_sessions_labels_gin |
alert_sessions |
CreateGINIndexes in pkg/database/migrations.go |
The first two are partial unique indexes (WHERE parent_execution_id IS [NOT] NULL) documented in ent/schema/agentexecution.go. The GIN indexes are created at startup.
Checklist
- Wrap the file in
BEGIN;/COMMIT;if Atlas didn't. A failed migration then rolls back cleanly andrecoverDirtyMigration(pkg/database/client.go) can retry on the next deploy. Exception: statements that can't run in a transaction (e.g.CREATE INDEX CONCURRENTLY) go in their own migration file withoutBEGIN/COMMIT. - Remove any
DROP INDEXfor an index in the table above, or any other index created by hand or with aWHEREclause (searchpkg/database/migrations/for where it was created). - Remove
DROP INDEX+CREATE INDEXpairs whoseCREATEmatches the existing definition in an earlier migration (common withsessionscore_session_id). - Remove
ALTER TABLEstatements on tables unrelated to the migration's purpose. If unsure, find the Ent schema change that caused it. - Run
make migrate-hashto updateatlas.sum.
Adding a new index Atlas can't model
Write it as raw SQL in the migration, add a comment naming it and its migration file in the Ent schema's Indexes(), and add a row to the table above.
04 同仓库更多 Skills
目录加载测试技能
simple-skill
一个简单的测试技能,用于验证目录布局加载。
示例技能
example-skill
用于配置查看器端到端(e2e)覆盖测试的示例技能。
网络故障排查
networking
网络故障排查技能,包括 DNS 解析、TCP 连接性以及数据包分析。
Kubernetes 核心概念与基础
kubernetes-basics
Kubernetes 核心概念,包括 Pod、Deployment、Service 以及常见故障排查模式。