Communitygithub.com

ComeOnOliver/skillshub

根據專案慣例,為 Prisma、Sequelize、Alembic、Knex、TypeORM 及其他 ORM 建立資料庫遷移檔案。適合在新增表格、修改綱要或用戶提及資料庫變更時使用。

skillshub 是什麼?

這項技能旨在自動化資料庫遷移檔案的建立流程,能根據專案使用的 ORM(物件關聯對映)工具及慣例,產生符合規範的遷移腳本。它支援 Prisma、Sequelize、Knex、TypeORM、Alembic、Django、Rails Active Record、Flyway 和 Liquibase 等多種主流遷移工具,並能透過偵測專案中的指示檔案(如 schema.prisma、knexfile.js)自動識別應使用的 ORM。技能會分析現有遷移檔案的命名規則、目錄結構與編碼模式,然後生成包含正向與回滾操作的完整遷移腳本。此外,它還會檢查遷移的安全性(如可逆性、資料遺失風險、資料表鎖定問題),並建議在開發或測試環境中先行執行。對於複雜的資料遷移,它鼓勵將綱要變更與資料遷移分離,並以批次操作處理大型資料集。透過遵循統一的命名慣例與最佳實踐,這項技能能有效減少人為錯誤,確保資料庫變更的可追溯性與穩定性。

相容平台~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 慣例與命名模式的資料庫遷移檔案。

使用時機

  • 用戶要求建立資料庫遷移
  • 在資料庫中新增資料表或資料行
  • 修改現有資料庫綱要
  • 建立索引、約束條件或關聯
  • 用戶提及「migration」、「schema change」或「database update」

操作說明

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 在 package.json 中
  • Alembic (Python):尋找 alembic.ini 或 alembic/ 目錄
  • Django:尋找 manage.py 及 */migrations/ 中的 Django 遷移
  • Active Record (Rails):尋找 db/migrate/ 目錄
  • Flyway:尋找 flyway.conf 或 db/migration/
  • Liquibase:尋找 liquibase.properties 或 changelog 檔案

使用 Glob 搜尋這些指示檔案。

2. 檢查現有遷移

讀取現有遷移檔案以了解:

  • 命名慣例(時間戳格式、描述格式)
  • 目錄結構
  • 遷移檔案格式(SQL、JavaScript、TypeScript、Python 等)
  • 編碼模式(up/down 函數、向前/回滾等)

使用 Grep 尋找最近的遷移:查看常見目錄,例如:

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

3. 產生遷移檔案

根據偵測到的 ORM,建立適當的遷移檔案:

Prisma

  • 執行 npx prisma migrate dev --name <描述> 或
  • 在 prisma/migrations/<時間戳>_<名稱>/migration.sql 中手動建立遷移 SQL

Sequelize

  • 產生:npx sequelize-cli migration:generate --name <描述>
  • 然後在 up/down 函數中填入綱要變更

Knex

  • 產生:npx knex migrate:make <描述>
  • 填入 exports.up 和 exports.down 函數

TypeORM

  • 產生:npm run typeorm migration:create src/migrations/<名稱>
  • 實作 up() 和 down() 方法

Alembic

  • 產生:alembic revision -m "<描述>"
  • 填入 upgrade() 和 downgrade() 函數

Django

  • 執行:python manage.py makemigrations
  • 或在 <應用程式>/migrations/ 中手動建立遷移

Rails

  • 產生:rails generate migration <類別名稱>
  • 填入 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(對於自動產生的 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

相關技能