← 返回
未分类 中文

Db Migrate

Deep database migration workflow—expand/contract, backward-compatible deploys, backfills, locking risks, and verification. Use when changing production schem...
深度数据库迁移工作流——扩展/收缩、向后兼容部署、回填、锁表风险及验证。适用于更改生产 schema 时。
codekungfu codekungfu 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 439
下载
💾 0
安装
1
版本
#latest

概述

DB Migrations

Production schema changes fail when old and new code disagree during rollout. Prefer expand/contract: add compatible changes first, remove old shapes later.

When to Offer This Workflow

Trigger conditions:

  • ALTER TABLE in production; large table rewrites
  • Blue/green deploys coupled to schema state
  • Need zero-downtime or low-downtime migrations

Initial offer:

Use six stages: (1) classify change, (2) expand phase, (3) backfill & dual-write, (4) flip reads/writes, (5) contract phase, (6) verify & rollback). Confirm database engine (PostgreSQL, MySQL, etc.).


Stage 1: Classify Change

Goal: Additive vs destructive; lock risk (full table rewrite vs instant metadata change).

Exit condition: Migration labeled as expand or contract with risk notes.


Stage 2: Expand Phase

Goal: Add nullable columns or new tables without breaking currently deployed code.

Practices

  • Avoid DEFAULT clauses that lock large tables badly on some engines (use phased backfill instead)

Stage 3: Backfill & Dual-Write

Goal: Throttled batch backfill; dual-write old and new representations during transition when needed.


Stage 4: Flip Reads/Writes

Goal: Deploy code that reads new columns only after backfill completes; use feature flags for staged rollout.


Stage 5: Contract Phase

Goal: Drop old columns only after no code references them (search repo, logs, feature usage).


Stage 6: Verify & Rollback

Goal: Monitor errors, slow queries, replication lag; rollback = redeploy previous app version + avoid destructive steps until stable.


Final Review Checklist

  • [ ] Change classified; expand/contract path clear
  • [ ] Additive migrations before dependent code
  • [ ] Backfill throttled and verified
  • [ ] Read/write cutover sequenced with flags
  • [ ] Contract only after references gone
  • [ ] Monitoring and rollback tested

Tips for Effective Guidance

  • Long transactions on migrations can cause outages—chunk work.
  • Use online schema tools (pt-online-schema-change, etc.) when appropriate.

Handling Deviations

  • SQLite/embedded engines have different locking—validate per engine.

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-03 08:05 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

dev-programming

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 687 📥 331,489
dev-programming

Mcporter

steipete
使用 mcporter CLI 直接列出、配置、认证及调用 MCP 服务器/工具(支持 HTTP 或 stdio),涵盖临时服务器、配置编辑及 CLI/类型生成功能。
★ 198 📥 68,323
dev-programming

YouTube

byungkyu
使用托管OAuth集成YouTube Data API,支持搜索视频、管理播放列表、获取频道数据及评论互动,适用于用户需要时使用此技能。
★ 142 📥 42,181