Database Migration

Use when planning or reviewing database schema/data migrations, ORM changes, zero-downtime deployment, backfills, compatibility, or rollback.

9 stars 3 forksDatabases

Install

skills CLI (Claude Code, Cursor, Codex and more)
npx skills add sandbaseai/workbuddy-skill --skill database-migration
Manual install
git clone --depth 1 https://github.com/sandbaseai/workbuddy-skill.git /tmp/workbuddy-skill
mkdir -p ~/.claude/skills
cp -r /tmp/workbuddy-skill/skills/database-migration ~/.claude/skills/database-migration

Personal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.

From the SKILL.md

# Database Migration

以可兼容、可观测、可暂停的阶段演进 schema 和数据。迁移的成功条件不仅是脚本退出 0,还包括旧/新应用兼容、数据完整性、锁与复制影响、回填进度、权限、恢复时间和明确的停止/回滚路径。

## 使用边界

- 开始前确认数据库/ORM 版本、表规模、读写模式、复制拓扑、备份、SLO、租户/PII、owner、发布窗口和目标环境。
- 默认只读审查 schema、迁移脚本、查询计划、锁/WAL/复制指标和应用兼容性;在隔离 clone 使用脱敏/合成数据演练。
- 不擅自执行生产 DDL、回填、重命名/删除、权限/RLS、索引、replica 操作或 restore;这些动作需要授权、备份和恢复演练。
- 日志、备份、迁移报告和样本不得泄露 secret、完整业务行或个人数据。

## 迁移契约与 expand-contract

每个迁移记录不可变版本、前置条件、目标 schema、数据不变量、owner、预计锁/资源、监控、停止条件、验证、兼容窗口和回滚/前向修复。优先采用:

1. **Expand**:新增可选列/表/索引或兼容字段,不破坏旧客户端。
2. **Migrate**:应用同时兼容旧/新,按有界批次回填或双读/双写,记录 watermark 和失败项。
3. **Validate**:校验计数、hash、NULL/重复、约束、读写、延迟、复制和下游消费者。
4. **Contract**:所有消费者切换并观察稳定窗口后,才收紧约束、停止双写或移除旧结构。

破坏性变更不能伪装成一次 rename/drop。字段/类型/语义变化要有兼容版本、消费者影响和迁移文档;数据库回滚不等于应用版本回滚。

## Schema 与 ORM

迁移文件是审计记录,不依赖当前模型自动推导覆盖历史。检查 Sequelize/TypeORM/Prisma 或其他 ORM 生成 SQL、默认值、NULL 语义、索引、FK、事务和 provider 方言;在目标数据库版本上审查实际 SQL。大表避免长事务和全表锁,必要时拆分 `NOT VALID`/validate、并发索引、分批更新和低优先级窗口。

```text
add nullable column ──> deploy dual-compatible code
        │                         │
        └── bounded backfill ─────┘
                 ↓
      validate counts/invariants/consumers
                 ↓
      enforce constraint ──> stop dual-write ──> retire old field
```

## 数据转换与回填

转换先定义旧值到新值的可逆/不可逆映射、空值/异常/重复规则、精度/时区、幂等键和审计摘要。回填按主键/时间分片有界执行,支持暂停/重启,限制 batch、锁、CPU、WAL、复制延迟和下游负载;失败行进入隔离清单,不静默跳过。

写入新结构前后比较抽样与聚合校验(计数、金额/范围、关系、不变量、hash),避免把 PII 放入证据。双写要处理顺序、重复、部分成功和未知结果;优先 outbox/事务或可证明的一致性协议。缓存、搜索索引、CDC、备份和下游 ETL 也要纳入迁移图。

## 锁、复制与发布
Read the full skill on GitHub

Details

Skill name
database-migration
Path
skills/database-migration/SKILL.md
License
MIT
Repo updated
8 September 2026

FAQ

What does the Database Migration skill do?

Use when planning or reviewing database schema/data migrations, ORM changes, zero-downtime deployment, backfills, compatibility, or rollback.

How do I install the Database Migration skill?

skills CLI (Claude Code, Cursor, Codex and more): npx skills add sandbaseai/workbuddy-skill --skill database-migration. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.

Is Database Migration popular?

It lives in sandbaseai/workbuddy-skill, which has 9 GitHub stars and 3 forks.

Related skills

Browse the most popular Claude skills, all databases skills, or write your own with the skills generator.