Communitygithub.com

数据库迁移助手

根据项目约定为 Prisma、Sequelize、Alembic、Knex、TypeORM 等 ORM 创建数据库迁移文件。在添加表、修改架构或用户提及数据库更改时使用。

数据库迁移助手 是什么?

这个技能帮助开发者自动创建符合项目 ORM 约定和命名规范的数据库迁移文件。它支持多种主流 ORM 和迁移工具,包括 Prisma、Sequelize、Knex、TypeORM、Alembic、Django、Rails 的 Active Record、Flyway 和 Liquibase。技能首先通过查找配置文件(如 prisma/schema.prisma、knexfile.js、alembic.ini 等)自动检测项目使用的 ORM,然后分析现有迁移文件以理解命名约定、目录结构和编码模式。基于这些信息,它生成正确的迁移命令或手动创建迁移文件,确保包含向上(应用更改)和向下(回滚更改)两个方向,并提供数据安全验证。该技能还提供最佳实践指导,如每个迁移只做一件事、使用描述性名称、测试回滚、对大表操作使用批处理等。它适用于需要执行数据库架构变更的 AI 编码助手平台,如 Claude Code、Cursor 和 Codex,有效减少手动迁移编写错误并加速开发流程。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComeOnOliver/skillshub/tree/HEAD/skills/aiskillstore/marketplace/crazydubya/database-migration-helper

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

数据库迁移助手 是做什么的?

此技能可帮助您创建符合项目 ORM 约定和命名模式的数据库迁移文件。

何时使用此技能

  • 用户请求创建数据库迁移
  • 向数据库添加新表或新列
  • 修改现有数据库架构
  • 创建索引、约束或关系
  • 用户提及“迁移”、“架构更改”或“数据库更新”

操作说明

1. 检测 ORM/迁移工具

首先,识别项目使用哪个 ORM 或迁移工具:

  • Prisma:在 package.json 中查找 prisma/schema.prisma 或 @prisma/client
  • Sequelize:在 package.json 中查找 .sequelizerc 或 sequelize-cli
  • Knex:在 package.json 中查找 knexfile.js 或 knex
  • TypeORM:查找 ormconfig.json 或 typeorm
  • Alembic(Python):查找 alembic.ini 或 alembic/ 目录
  • Django:查找 manage.py 以及 */migrations/ 中的 Django 迁移
  • Active Record(Rails):查找 db/migrate/ 目录
  • Flyway:查找 flyway.conf 或 db/migration/
  • Liquibase:查找 liquibase.properties 或变更日志文件

使用 Glob 搜索这些指示文件。

2. 检查现有迁移

阅读现有迁移文件以了解:

  • 命名约定(时间戳格式、描述格式)
  • 目录结构
  • 迁移文件格式(SQL、JavaScript、TypeScript、Python 等)
  • 编码模式(up/down 函数、forward/rollback 等)

使用 Grep 查找最近的迁移:在常见目录中查找,例如:

  • prisma/migrations/
  • db/migrate/
  • migrations/ 或 database/migrations/
  • alembic/versions/

3. 生成迁移文件

根据检测到的 ORM,创建适当的迁移文件:

Prisma

  • 运行 npx prisma migrate dev --name <description> 或者
  • 手动在 prisma/migrations/<timestamp>_<name>/migration.sql 中创建迁移 SQL

Sequelize

  • 生成:npx sequelize-cli migration:generate --name <description>
  • 然后填写 up/down 函数中的架构更改

Knex

  • 生成:npx knex migrate:make <description>
  • 填写 exports.up 和 exports.down 函数

TypeORM

  • 生成:npm run typeorm migration:create src/migrations/<Name>
  • 实现 up() 和 down() 方法

Alembic

  • 生成:alembic revision -m "<description>"
  • 填写 upgrade() 和 downgrade() 函数

Django

  • 运行:python manage.py makemigrations
  • 或者在 <app>/migrations/ 中手动创建迁移

Rails

  • 生成:rails generate migration <ClassName>
  • 填写 change 方法(对于复杂迁移则使用 up/down)

4. 遵循命名约定

使用一致且描述性的名称:

  • 好:add_user_email_index,create_products_table,add_payment_status_to_orders
  • 差:migration1,update,fix

根据项目模式格式化:

  • 时间戳前缀:20231215120000_add_email_to_users
  • 顺序编号:001_create_users,002_add_indexes

5. 同时包含 Up 和 Down/回滚

在支持的情况下始终提供两个方向:

  • Up/Upgrade/Forward:应用架构更改
  • Down/Downgrade/Rollback:还原架构更改

对于使用可逆操作的 ORM(Rails、某些 Sequelize 配置),单个 change 方法可能就足够了。

6. 迁移内容指南

创建表:

  • 使用适当的类型定义所有列
  • 在适当的位置设置 NOT NULL 约束
  • 添加主键
  • 如果项目使用时间戳,则包含创建时间和更新时间(created_at、updated_at)
  • 在同一迁移中添加外键和索引,或者如果项目偏好分开则单独添加

修改表:

  • 具体明确:ADD COLUMN、DROP COLUMN、MODIFY COLUMN
  • 适当处理现有数据(默认值、回填)
  • 考虑向后兼容性

添加索引:

  • 清晰命名索引:idx_users_email、idx_orders_user_id_created_at
  • 使用适当的索引类型(B-tree、Hash、GIN 等)
  • 对大型表考虑部分索引

数据迁移:

  • 如果可能,将架构迁移与数据迁移分开
  • 对大型数据集保持谨慎(使用批处理)
  • 使用接近真实场景的数据量测试回滚

7. 验证迁移安全性

在最终确定之前,检查:

  • 可逆性:迁移能否回滚?
  • 数据丢失:是否会导致数据丢失?警告用户!
  • 停机时间:是否会锁定表?对于大型表考虑在线迁移
  • 依赖关系:是否存在必须先运行的依赖迁移?

8. 测试建议

向用户建议:

  • 先在开发数据库上运行迁移
  • 测试回滚功能
  • 对于生产环境:在预发布环境中测试
  • 审查生成的 SQL(针对自动生成 SQL 的 ORM)

ORM 特定模板

参考 templates/ 目录中的模板:

  • prisma-migration.sql - Prisma 迁移示例
  • sequelize-migration.js - Sequelize 迁移示例
  • knex-migration.js - Knex 迁移示例
  • typeorm-migration.ts - TypeORM 迁移示例
  • alembic-migration.py - Alembic 迁移示例
  • rails-migration.rb - Rails 迁移示例

最佳实践

  1. 每个迁移一个目的:不要混合不相关的更改
  2. 描述性名称:名称应解释迁移的作用
  3. 时间戳:使用 ORM 的时间戳格式进行排序
  4. 尽可能幂等:多次运行安全
  5. 测试回滚:确保 down/rollback 正确工作
  6. 文档化复杂逻辑:为非显而易见操作添加注释
  7. 批处理大型操作:对于影响多行的数据迁移
  8. 使用事务:在支持的平台上将操作包装在事务中

支持文件

  • templates/:各种 ORM 的迁移模板
  • reference.md:命名约定和迁移模式

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

ComeOnOliver/skillshub

Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.

ComeOnOliver/skillshub

Next.js 16+ 和 Turbopack — 增量打包、文件系统缓存、开发速度,以及何时使用 Turbopack 与 webpack。

ComeOnOliver/skillshub

SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

ComeOnOliver/skillshub

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

ComeOnOliver/skillshub

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

ComeOnOliver/skillshub

Next.js 15 애플리케이션을 위한 프론트엔드 개발 가이드라인. React 19, TypeScript, Shadcn/ui, Tailwind CSS를 사용한 모던 패턴. Server Components, Client Components, App Router, 파일 구조, Shadcn/ui 컴포넌트, 성능 최적화, TypeScript 모범 사례 포함. 컴포넌트, 페이지, 기능 생성, 데이터 페칭, 스타일링, 라우팅, 프론트엔드 코드 작업 시 사용.

ComeOnOliver/skillshub

Provides Tamagui patterns for config v4, compiler optimization, styled context, and cross-platform styling. Must use when working with Tamagui projects (tamagui.config.ts, @tamagui imports).

ComeOnOliver/skillshub

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

ComeOnOliver/skillshub

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

ComeOnOliver/skillshub

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

ComeOnOliver/skillshub

Next.js development tooling via MCP. Inspect routes, components, build info, and debug Next.js apps. Use when working on Next.js applications, debugging routing, or inspecting app structure. NOT for general React or non-Next.js projects.

ComeOnOliver/skillshub

Implement UI using Shadcn MCP (atoms/theme) and 21st.dev MCP (complex sections). Use when adding buttons, layouts, or generating landing pages.

ComeOnOliver/skillshub

A conceptual skill for building an API client in Next.js that handles JWT tokens

ComeOnOliver/skillshub

Best practices and patterns for Next.js App Router, Server Actions, and Routing in this project.

ComeOnOliver/skillshub

The Design System, Theme, and UX rules for the Physical AI Hub.

ComeOnOliver/skillshub

Comprehensive frontend development skill for building modern, performant web applications using ReactJS, NextJS, TypeScript, Tailwind CSS. Includes component scaffolding, performance optimization, bundle analysis, and UI best practices. Use when developing frontend features, optimizing performance, implementing UI/UX designs, managing state, or reviewing frontend code.

ComeOnOliver/skillshub

This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.

ComeOnOliver/skillshub

Build Next.js 16 applications with correct patterns and distinctive design. Use when creating pages, layouts, dynamic routes, upgrading from Next.js 15, or implementing proxy.ts. Covers breaking changes (async params/searchParams, Turbopack, cacheComponents) and frontend aesthetics. NOT when building non-React or backend-only applications.

ComeOnOliver/skillshub

Comprehensive Framer Motion animation library for React. Covers motion components, variants, gestures, page transitions, and scroll animations. Use when adding animations to React/Next.js applications.

ComeOnOliver/skillshub

Build interfaces that resonate, not just render. This skill enforces bold, intentional

相关技能