Skip to content
migrate-db logo

Migrate DB Skill

migrate-db

Prisma/SQL 마이그레이션 관리. Use when: (1) 스키마 변경, (2) 마이그레이션 생성/적용, (3) DB 동기화, (4) 마이그레이션 상태 확인, (5) 롤백 필요 시.

SKILL.md

Full skill instructions

호출 시 메시지: 이 Skill이 호출되면 반드시 [SEMO] Skill: migrate-db 호출 - {service_name} 시스템 메시지를 첫 줄에 출력하세요.

Migrate DB Skill

Prisma/​SQL 마이그레이션 안전 관리

지원 기술 스택

스택도구서비스 예시
Prismaprisma migratems-notifier, ms-scheduler, ms-ledger, ms-allocator
SQL수동 마이그레이션ms-gamer (Go)
SupabaseSupabase CLIms-collector

워크플로우

Phase 0: 환경 확인 (NON-NEGOTIABLE)

# 현재 브랜치 확인
git branch --show-current

# 미커밋 변경사항 확인
git status --porcelain

# 기술 스택 감지
if [ -f "prisma/​schema.prisma" ]; then
  MIGRATION_TOOL="prisma"
elif [ -f "go.mod" ]; then
  MIGRATION_TOOL="sql"
else
  MIGRATION_TOOL="unknown"
fi
echo "마이그레이션 도구: $MIGRATION_TOOL"

경고: 프로덕션 환경에서는 반드시 백업 후 진행하세요.


Phase 1: 마이그레이션 상태 확인

Prisma
# 현재 마이그레이션 상태
npx prisma migrate status

# 스키마 유효성 검사
npx prisma validate

# 스키마 포맷 확인
npx prisma format --check
SQL (Go 서비스)
# 마이그레이션 파일 목록
ls -la db/​migrations/ 2>/​dev/​null || ls -la migrations/

# 적용된 마이그레이션 확인 (schema_migrations 테이블)
psql -c "SELECT * FROM schema_migrations ORDER BY version DESC LIMIT 10"

Phase 2: 마이그레이션 생성

Prisma - 개발 환경
# 스키마 변경 후 마이그레이션 생성
npx prisma migrate dev --name {migration_name}

# 예시: 새 필드 추가
npx prisma migrate dev --name add_user_email
Prisma - 프로덕션 환경
# 마이그레이션 파일만 생성 (적용하지 않음)
npx prisma migrate dev --create-only --name {migration_name}

# 생성된 SQL 검토 후 수동 적용
cat prisma/​migrations/​{timestamp}_{name}/​migration.sql
SQL 수동 마이그레이션
# 마이그레이션 파일 생성
TIMESTAMP=$(date +%Y%m%d%H%M%S)
touch db/​migrations/​${TIMESTAMP}_{migration_name}.sql

# 예시 내용
cat << 'EOF' > db/​migrations/​${TIMESTAMP}_add_user_email.sql
-- Up
ALTER TABLE users ADD COLUMN email VARCHAR(255);

-- Down
ALTER TABLE users DROP COLUMN email;
EOF

Phase 3: 마이그레이션 적용

Prisma
# 개발 환경
npx prisma migrate dev

# 프로덕션 환경 (CI/​CD에서 사용)
npx prisma migrate deploy
SQL (golang-migrate)
# 적용
migrate -path db/​migrations -database "$DATABASE_URL" up

# 특정 버전까지만 적용
migrate -path db/​migrations -database "$DATABASE_URL" up 1

Phase 4: 롤백 (주의 필요)

경고: 롤백은 데이터 손실을 유발할 수 있습니다. 반드시 백업 후 진행하세요.

Prisma
# Prisma는 직접적인 롤백을 지원하지 않음
# 대신 새 마이그레이션으로 변경 사항 되돌리기

# 1. 되돌릴 스키마 변경 작성
# 2. 새 마이그레이션 생성
npx prisma migrate dev --name revert_{previous_migration}
SQL (golang-migrate)
# 마지막 마이그레이션 롤백
migrate -path db/​migrations -database "$DATABASE_URL" down 1

# 모든 마이그레이션 롤백 (위험!)
# migrate -path db/​migrations -database "$DATABASE_URL" down

Phase 5: Prisma 클라이언트 재생성

# 스키마 변경 후 클라이언트 재생성
npx prisma generate

# 타입 확인
npx tsc --noEmit

출력 포맷

마이그레이션 성공

[SEMO] Skill: migrate-db 호출 - ms-{service}

=== 마이그레이션 결과 ===

## 환경
- 서비스: ms-{service}
- 도구: Prisma
- 환경: development

## 실행 내역
| 단계 | 상태 | 상세 |
|------|------|------|
| 상태 확인 | ✅ | 대기 중인 마이그레이션 1건 |
| 스키마 검증 | ✅ | 유효 |
| 마이그레이션 적용 | ✅ | 20250122_add_user_email |
| 클라이언트 생성 | ✅ | @prisma/​client 재생성 |

## 적용된 마이그레이션
- `20250122143000_add_user_email`
  - ALTER TABLE `users` ADD COLUMN `email` VARCHAR(255)

## 다음 단계
1. `npx tsc --noEmit`로 타입 확인
2. 테스트 실행: `npm test`
3. 커밋: `git add prisma/ && git commit -m "db: add user email field"`

마이그레이션 실패

[SEMO] Skill: migrate-db 호출 - ms-{service}

=== 마이그레이션 실패 ===

## 오류

Error: P3009 migrate found failed migrations in the target database.


## 원인
- 이전 마이그레이션이 실패한 상태로 남아있음

## 해결 방법
1. 실패한 마이그레이션 확인:
   ```bash
   npx prisma migrate status
  1. 수동으로 실패한 마이그레이션 해결:

    npx prisma migrate resolve --rolled-back {migration_name}
    
  2. 재시도:

    npx prisma migrate dev
    

## 안전 체크리스트

### 개발 환경

- [ ] 로컬 DB 백업 불필요 (재생성 가능)
- [ ] 스키마 변경 검토
- [ ] 테스트 통과 확인

### 스테이징/프로덕션 환경

- [ ] DB 백업 완료
- [ ] 마이그레이션 SQL 검토
- [ ] 롤백 계획 수립
- [ ] 다운타임 영향도 확인
- [ ] 팀 공유 및 승인

## 서비스별 스키마 정보

| 서비스 | 스키마명 | Prefix | 주요 테이블 |
|--------|---------|--------|------------|
| ms-notifier | notifier | nf_ | notifications, channels, jobs |
| ms-scheduler | scheduler | sc_ | schedules, executions, job_queue |
| ms-ledger | ledger | lg_ | accounts, transactions, subscriptions |
| ms-allocator | allocator | al_ | tracked_subjects, snapshots, aggregates |
| ms-gamer | public | ladder_ | round, bet, pattern |

## Related Skills

- [setup-prisma](../setup-prisma/SKILL.md) - Prisma 초기 설정
- [debug-service](../debug-service/SKILL.md) - DB 연결 디버깅

## References

- [Prisma Migrate](https://www.prisma.io/docs/concepts/components/prisma-migrate)
- [golang-migrate](https://github.com/golang-migrate/migrate)
- [Microservices Context](/.claude/memory/microservices.md) - 서비스별 스키마 정보

More DevOps & CI/CD skills

Project scaffolding, deployment configuration, and CI/CD setup for Google ADK agents.

6K 472.6K
View

Set up tracing, logging, and monitoring for deployed ADK agents across Cloud Trace, BigQuery, and third-party platforms.

6K 472.6K
View

Enterprise Azure infrastructure architect generating Bicep or Terraform from workload descriptions.

1.5K 454.3K
View
azure-kubernetes logo
DevOps & CI/CD

azure-kubernetes

Plan and configure production-ready Azure Kubernetes Service clusters with Day-0 and Day-1 best practices.

1.5K 447.1K
View

Raw mechanical interfaces fusing Swiss typographic print with military terminal aesthetics. Rigid grids, extreme type scale contrast, utilitarian color, analog degradation effects. For data-heavy dashboards, portfolios, or editorial sites that need to feel like declassified blueprints.

92.7K 354.9K
View
just-scrape logo
DevOps & CI/CD

just-scrape

Web search, scraping, extraction, crawling, and monitoring via ScrapeGraph AI CLI.

69 245K
View

Skill for working with Firebase Hosting (Classic). Use this when you want to deploy static web apps, Single Page Apps (SPAs), or simple microservices. Do NOT use for Firebase App Hosting.

462 159.7K
View

Deploy and manage web apps with Firebase App Hosting. Use this skill when deploying Next.js/Angular apps with backends.

462 159.1K
View
deploy-to-vercel logo
DevOps & CI/CD

deploy-to-vercel

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

31.9K 146.6K
View
programmatic-seo logo
DevOps & CI/CD

programmatic-seo

Build SEO-optimized pages at scale using templates, data, and proven playbook patterns.

53.3K 140.1K
View

Design and build isolated, reusable Convex backend components with clear boundaries and app-facing wrappers.

63 123.5K
View

Deploy and manage projects on Vercel using token-based authentication. Use when working with Vercel CLI using access tokens rather than interactive login — e.g. "deploy to vercel", "set up vercel", "add environment variables to vercel".

31.9K 116.1K
View

Coding & apps AI tools

Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View
I
Coding & apps

Imagica

Build a no-code AI app in minutes.

Freemium
View
E
Coding & apps

Emergent.sh

An IDE for code migration from legacy to modern frameworks through coding agents.

Freemium
View
Wonder Dynamics logo
Coding & apps

Wonder Dynamics

Automate CGI animation in live-action scenes

Paid
View
M
Coding & apps

Mixo

Launch a website in seconds with AI.

Paid
View
AI Code Convert logo
Coding & apps

AI Code Convert

Streamline Your Coding Experience with AI Code Helper

Free
View