wu529778790/shenzjd-skills

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.

소스 보기

사용 방법

  1. 설치 명령을 복사하고 자신의 에이전트 환경에 설치하기 전에 소스 패키지를 확인하세요.
  2. 필요한 도구, 인증 정보, 지원 환경은 원본 문서에서 확인하세요.
  3. 입력과 원하는 산출물을 설명하고 출처와 결과를 대조하세요.
npx skills add https://github.com/wu529778790/shenzjd-skills --skill db-migration-helper

시작 전 확인

  • 설치에는 모델 구독, API 한도, 파일 접근 권한이 포함되지 않습니다.
  • 별점 수와 설치 수는 활동 지표이며 독립적인 품질·보안 검증이 아닙니다.
원본 Skill 문서

원본 저장소의 제목, 예시, 코드, 표, 링크, 이미지를 유지해 표시합니다.

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.prismaPrisma生成 SQL diff
alembic/SQLAlchemy + Alembic生成 Alembic migration
migrations/通用扫描已有迁移推断
*.entity.ts / *.model.tsTypeORM / Sequelize从装饰器提取
schema.rb / db/migrate/RailsRails migration

Step 2: 提取当前 Schema

bash
# 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 模板,生成:

  1. Up 迁移 — 正向变更 SQL
  2. Down 回滚 — 反向回滚 SQL
  3. 风险评估 — 标注高风险操作
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

bash
/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 COLUMNPostgreSQL 可直接 ALTER COLUMN ... TYPE ... USING;MySQL 用 新建列 → 迁移数据 → 删旧列MySQL 直接改类型可能丢数据,PG 的 USING 是原子转换
不加索引为查询字段加索引影响查询性能
迁移文件没有名字用描述性命名方便团队协作和回溯
不检查外键依赖先检查表间关系删除被引用的列会失败

관련 작업

같은 저장소의 Skills

더 많은 Skills

모든 Skills
wu529778790
커뮤니티

video-cover-packager

Package one video/script/transcript into a complete publish kit: cover titles, platform titles, per-platform tags, description, and creative cover art direction with pre-review before image generation. Covers Xiaohongshu, Douyin, WeChat Channels (视频号), Bilibili, and YouTube. Use when the user asks for video cover design, 封面包装, 视频包装, 发布文案, 标题公式, 封面标题, platform tags for a video, or says '给这期视频做封面/标题/描述/标签'. Keywords: video cover, thumbnail title, publish kit, self-media packaging, 小红书封面, 抖音封面, B站封

설치 수
1
GitHub Stars
4
업데이트
9월 25일
wu529778790
커뮤니티

dependency-audit

Use when auditing project dependencies for security vulnerabilities, outdated packages, or license compliance across npm/yarn/pnpm, pip, go, and cargo.

설치 수
1
GitHub Stars
0
업데이트
8월 16일
wu529778790
커뮤니티

docker-build-deploy

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.

설치 수
1
GitHub Stars
0
업데이트
8월 16일
wu529778790
커뮤니티

git-hooks-setup

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.

설치 수
1
GitHub Stars
0
업데이트
8월 16일