AgentSkillsCN

db-change

适用于Schema/数据迁移(EF Core或其他工具)。切勿仅针对纯应用层的变更进行触发。重点在于安全的上线与回滚流程。

SKILL.md
--- frontmatter
name: db-change
description: Use for schema/data migrations (EF Core or other). Do NOT trigger for pure app-layer changes. Focus on safe rollout and rollback.

Principles:

  • Prefer backward-compatible migrations (expand → migrate → contract).
  • Minimize locking and long transactions; design for online changes where feasible.
  • Data backfills must be idempotent, resumable, and observable.

Checklist:

  1. Plan
  • Identify tables/columns/indexes affected
  • Determine rollout strategy:
    • Expand: add nullable column / new table / additive index
    • Migrate: backfill and dual-write/read if needed
    • Contract: drop old column, enforce constraints, finalize
  • Define rollback approach and what "safe to retry" means
  1. Migration implementation
  • Create migration (EF Core / SQL tool)
  • Ensure indexes/constraints are appropriate and named consistently
  • Check for default values and nullability
  • Evaluate lock risk (large table rewrite, index build)
  1. Data backfill (if required)
  • Write an idempotent backfill job/script:
    • batches with stable ordering
    • progress logging / metrics
    • safe retry without corruption
    • can be paused/resumed
  • Verify performance impact (throttling, time windows)
  1. App changes
  • Ensure app supports both old and new schema during rollout
  • Update queries/projections to avoid breaking older deployments (if relevant)
  1. Verification
  • Run migration locally in a realistic dataset if possible
  • Add/update tests (integration tests if repo supports them)
  • Document runbook for prod (timing, expected duration, monitoring)

Finish with:

  • Migration plan (expand/migrate/contract steps)
  • Commands run + results
  • Operational notes (runtime, monitoring, rollback)
  • Risks/follow-ups