
db-migration-helper
Use when generating database migration SQL from model or schema changes — compares current vs desired schema, detects diffs, outputs reversible safe migrations.
- Installs
- 980
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/wu529778790/shenzjd-skills --skill db-migration-helper- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads db-migration-helper automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
DB Migration Helper
分析 model 变更,生成安全的数据库迁移 SQL。
Overview
对比代码中的实体/模型定义与当前数据库 schema,检测结构变更(新增表、增删列、改类型),生成向前兼容的迁移 SQL。支持 MySQL、PostgreSQL、SQLite。
When to Use
- User wants to create database migrations
- User modified model/entity definitions
- User mentions migration, schema change, or sync
- User says "生成迁移" / "create migration"
- User inputs
/db-migration-helper
When NOT to Use:
- User only wants to view database structure
- User wants data migration (not schema)
- User uses ORM auto-migration
- User wants to generate seed data
- User wants to backup/restore database
Core Pattern
Step 1: 检测项目类型和 ORM
| 检测文件 | ORM/框架 | 迁移方式 |
|---|---|---|
prisma/schema.prisma | Prisma | 生成 SQL diff |
alembic/ | SQLAlchemy + Alembic | 生成 Alembic migration |
migrations/ | 通用 | 扫描已有迁移推断 |
*.entity.ts / *.model.ts | TypeORM / Sequelize | 从装饰器提取 |
schema.rb / db/migrate/ | Rails | Rails migration |
Step 2: 提取当前 Schema
# Prisma (v2.18+,旧命令 introspect 已更名为 db pull,统一用 db pull)
npx prisma db pull 2>/dev/null
# 通用 — 从代码提取
grep -r "CREATE TABLE\|@Entity\|@Table\|model " --include="*.ts" --include="*.py" --include="*.go" -l
提取:
- 表名和列定义
- 列类型、约束(NOT NULL、DEFAULT、UNIQUE)
- 索引和外键
Step 3: 对比变更
对比代码中的 model 定义与已有 schema(或上一次迁移),检测:
| 变更类型 | 风险等级 | 说明 |
|---|---|---|
| 新增表 | 低 | 直接 CREATE TABLE |
| 新增列(有 DEFAULT) | 低 | ALTER TABLE ADD COLUMN |
| 新增列(无 DEFAULT) | 中 | 需要处理已有数据 |
| 删除列 | 高 | 可能丢失数据,需要确认 |
| 修改列类型 | 高 | 可能不兼容 |
| 新增索引 | 低 | CREATE INDEX |
| 删除索引 | 低 | DROP INDEX |
Step 4: 生成迁移文件
使用 templates/migration.sql 模板,生成:
- Up 迁移 — 正向变更 SQL
- Down 回滚 — 反向回滚 SQL
- 风险评估 — 标注高风险操作
-- Migration: 20260603_add_user_avatar
-- Risk: LOW
-- Up
ALTER TABLE users ADD COLUMN avatar_url VARCHAR(500);
CREATE INDEX idx_users_email ON users(email);
-- Down
DROP INDEX idx_users_email;
ALTER TABLE users DROP COLUMN avatar_url;
Quick Reference
/db-migration-helper # 检测变更,生成迁移
/db-migration-helper --dry-run # 只预览 SQL 不执行
/db-migration-helper --name add_user # 指定迁移名称
| 参数 | 说明 | 默认值 |
|---|---|---|
--dry-run | 只预览不执行 | false |
--name | 迁移文件名 | 自动生成 |
--output | 输出目录 | ./migrations/ |
Common Mistakes
| 错误 | 正确做法 | 原因 |
|---|---|---|
| 不生成 down 回滚 | 始终生成回滚 SQL | 出问题需要回退 |
| 删除列不备份 | 先备份数据再删列 | 数据丢失不可恢复 |
| 改类型用 ALTER COLUMN | PostgreSQL 可直接 ALTER COLUMN ... TYPE ... USING;MySQL 用 新建列 → 迁移数据 → 删旧列 | MySQL 直接改类型可能丢数据,PG 的 USING 是原子转换 |
| 不加索引 | 为查询字段加索引 | 影响查询性能 |
| 迁移文件没有名字 | 用描述性命名 | 方便团队协作和回溯 |
| 不检查外键依赖 | 先检查表间关系 | 删除被引用的列会失败 |
FAQ
What does the db-migration-helper skill do?
Use when generating database migration SQL from model or schema changes — compares current vs desired schema, detects diffs, outputs reversible safe migrations.
How do I install db-migration-helper?
Run npx skills add https://github.com/wu529778790/shenzjd-skills --skill db-migration-helper in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/db-migration-helper/ (personal) or .claude/skills/db-migration-helper/ (project).
Which AI agents can use db-migration-helper?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is db-migration-helper safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains db-migration-helper?
It is published by wu529778790 in wu529778790/shenzjd-skills. It has 980 recorded installs.
More from wu529778790/shenzjd-skills
docker-build-deploy
wu529778790/shenzjd-skills
Use when containerizing a Node.js app and setting up GitHub Actions CI/CD to build, push to GHCR, and deploy via SSH. Multi-stage build, non-root user, caching.
dependency-audit
wu529778790/shenzjd-skills
Use when auditing project dependencies for security vulnerabilities, outdated packages, or license compliance across npm/yarn/pnpm, pip, go, and cargo.
git-hooks-setup
wu529778790/shenzjd-skills
Use when setting up git hooks (pre-commit, commit-msg, pre-push) with husky or native hooks for linting, formatting, commit conventions, and secret scanning.
github-profile-beautifier
wu529778790/shenzjd-skills
Use when creating or improving a GitHub profile README — themed stats cards, project showcase, tech-stack badges, and typing banner. 5 themes, smart project ranking (snake contribution graph needs separate setup).
api-doc-generator
wu529778790/shenzjd-skills
Use when generating OpenAPI/Swagger API docs from existing code — scans routes/annotations, extracts params and responses, outputs a YAML/JSON spec.
performance-profiler
wu529778790/shenzjd-skills
Use when profiling a Node/Go/Python project for performance bottlenecks — bundle size, dependency bloat, large files, unused code — and outputting prioritized optimization recommendations.
Popular code quality & workflow skills
grill-me
mattpocock/skills
A relentless interview to sharpen a plan or design.
improve-codebase-architecture
mattpocock/skills
Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.
handoff
mattpocock/skills
Compact the current conversation into a handoff document for another agent to pick up.
domain-modeling
mattpocock/skills
Build and sharpen a project's domain model. Use when discussing codebase terminology, writing or editing a GLOSSARY.md, or recording or editing an ADR.
codebase-design
mattpocock/skills
Shared vocabulary for designing deep modules. Use when the user wants to design or improve a module's interface, find deepening opportunities, decide where a seam goes, make code more testable or AI-navigable, or when another skill needs the deep-module vocabulary.
diagnosing-bugs
mattpocock/skills
Diagnosis loop for hard bugs and performance regressions. Use when the user says "diagnose"/"debug this", or reports something broken/throwing/failing/slow.