Skip to content
Agentmart
Submit a tool
This entry duplicates db-migrator, which is the one we list in search.

db-migrator

数据库迁移助手 - Schema 对比、迁移脚本生成

Skill by luomious

IndexedMIT
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/luomious-db-migrator

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

数据库迁移助手 - Schema 对比、迁移脚本生成

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions: not checked yet.

What's inside

Skill name
db-migrator
Description
数据库迁移助手 - Schema 对比、迁移脚本生成
License
MIT
Instructions
138 lines in SKILL.md · view on GitHub

Files (2)

  • SKILL.md
  • _source.json

SKILL.md (first lines)

# 数据库迁移助手

## 触发条件
当用户要求数据库迁移、生成 migration、schema 变更、数据库升级时激活此技能。

## 工作流程

### 第 1 步:识别框架
扫描项目文件,判断使用的 ORM/迁移框架:
- `alembic.ini` / `alembic/` → Alembic
- `prisma/schema.prisma` → Prisma
- `pom.xml` 含 flyway → Flyway
- `manage.py` + `settings.py` → Django
- `Gemfile` + `db/migrate/` → Rails

### 第 2 步:分析 Schema 变更
- 对比 models 定义与现有迁移历史
- 识别新增/修改/删除的表和字段
- 检测索引、约束、外键变更

### 第 3 步:生成迁移脚本
根据框架生成对应的迁移文件,并同时生成回滚脚本。

### 第 4 步:风险评估
- 大表 DDL 变更(锁表风险)
- 数据迁移需求
- 向后兼容性

## 迁移模板

### Alembic (Python)
```python
"""add email column to users

Revision ID: abc123
"""
from alembic import op
import sqlalchemy as sa

def upgrade():
    op.add_column('users', sa.Column('email', sa.String(255), nullable=True))
    op.create_index('ix_users_email', 'users', ['email'], unique=True)

def downgrade():
    op.drop_index('ix_users_email')
    op.drop_column('users', 'email')
```

### Flyway (Java)
```sql
-- V2__add_email_to_users.sql
ALTER TABLE users ADD COLUMN email VARCHAR(255);
CREATE UNIQUE INDEX ix_users_email ON users(email);

-- 回滚脚本 (单独文件 U2__rollback_add_email.sql)
-- 逆向操作
```

### Prisma (Node.js)
```prisma
// schema.prisma 变更
model User {
  id    Int     @id @default(autoincrement())
  name  String
  email String? @unique  // 新增字段
}
```
```bash
# 默认仅生成迁移,不执行数据库变更
npx prisma migrate dev --name add-email-to-users --create-only
```

检查生成的 SQL、连接目标和备份后,再由用户确认执行:

```bash
# 开发环境应用迁移
npx prisma migrate dev

# 生产环境应用已审核并提交的迁移
npx prisma migrate deploy
```

### Django (Python)
```python
# users/migrations/0002_add_email.py
from django.db import migrations, models

class Migration(migrations.Migration):
    dependencies = [('users', '0001_initial')]

    operations = [
        migrations.AddField(
            model_name='user',
            name='email',
            field=models.EmailField(unique=True, null=True),
        ),
    ]
```

`unique=True` 已由 Django 生成唯一约束和对应索引,不要再创建重复索引。

### Rails (Ruby)
```ruby
# db/migrate/20260617_add_email_to_users.rb
class AddEmailToUsers < ActiveRecord::Migration[7.0]
  def change
    add_column :users, :email, :string
    add_index :users, :email, unique: true
  end
end
```
```bash
rails db:migrate         # 执行迁移
rails db:rollback        # 回滚上一次
rails db:rollback STEP=3 # 回滚最近 3 次
```

## 回滚策略

From luomious/dsh-skills-hub, MIT.

Signals

Stars
0
Forks
0
Open issues
0
Last commit (this folder)
Sep 1, 2026 (1 month ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

Same skill elsewhere

Copies of this SKILL.md published by others; search shows only one of them.

More from luomious

Cite this page

db-migrator skill. Agent Mart. https://agentmart.dev/skills/luomious-db-migrator (last updated 2026-10-24)