db-migrate

작성자: sentry

Drizzle Kit을 사용하여 데이터베이스 마이그레이션을 생성합니다. 테이블, 컬럼 또는 인덱스를 추가/수정할 때 사용합니다. schema.ts와 마이그레이션이 동기화 상태를 유지하도록 보장합니다.

npx skills add https://github.com/getsentry/abacus --skill db-migrate

Database Migration Skill

Create schema changes with proper migrations.

CRITICAL: Never Write Migrations By Hand

ALWAYS use drizzle-kit generate to create migrations. NEVER write SQL migration files manually.

Why this matters:

  • Drizzle tracks schema state via snapshot files in drizzle/meta/
  • Hand-written migrations don't update snapshots
  • This causes drizzle-kit generate to fail with confusing prompts about tables being "created or renamed"
  • It breaks the entire migration system for future changes

If you're tempted to write SQL by hand (e.g., for data migrations), create a separate script in scripts/ instead.

Before Starting

  1. Read current schema: src/lib/schema.ts
  2. Read recent migrations: drizzle/*.sql (last 2-3)
  3. Understand current state before making changes

Workflow

Step 1: Modify Schema First

Edit src/lib/schema.ts with your changes:

  • Add new tables with pgTable()
  • Add columns to existing tables
  • Add/modify indexes

Step 2: Generate Migration

Run Drizzle Kit to generate migration SQL:

pnpm drizzle-kit generate

This creates a new file in drizzle/ like 0011_descriptive_name.sql.

Step 3: Review Generated Migration

Read the generated migration and verify:

  • SQL looks correct
  • No destructive changes (DROP without intent)
  • Index names follow convention
  • Column types match schema.ts

Step 4: Test Locally (Optional - Be Careful!)

WARNING: Only test migrations locally if POSTGRES_URL points to a LOCAL database. If it points to production, skip this step - migrations will run automatically on Vercel deploy.

To check your database URL:

echo $POSTGRES_URL  # Should be localhost or local container

If local database is configured:

pnpm build  # Runs migrations automatically
pnpm cli stats  # Verify queries work

Step 5: Verify in PR

  • Migration SQL looks correct (review diff)
  • schema.ts and migration are in same commit
  • No IF NOT EXISTS clauses (signals potential drift)

Common Patterns

Adding a Column

// schema.ts
export const myTable = pgTable('my_table', {
  // existing columns...
  newColumn: varchar('new_column', { length: 255 }),
});

Adding an Index

export const myTable = pgTable('my_table', {
  // columns...
}, (table) => [
  index('idx_my_table_column').on(table.column),
]);

Adding a Table

export const newTable = pgTable('new_table', {
  id: serial('id').primaryKey(),
  // columns...
}, (table) => [
  // indexes...
]);

Anti-Patterns (NEVER Do This)

  • Writing migration SQL by hand - This breaks drizzle's snapshot tracking and causes future generate commands to fail. ALWAYS use drizzle-kit generate.
  • Using IF NOT EXISTS or IF EXISTS - These clauses signal you're writing SQL by hand. Generated migrations never include them.
  • Editing schema.ts without running drizzle-kit generate
  • Modifying existing migrations after they've been applied to prod
  • Adding data migrations to schema migration files (use separate scripts)

Checklist

Before committing:

  • schema.ts changes match generated migration
  • Migration tested locally with pnpm build (only if local DB configured)
  • No IF NOT EXISTS clauses (clean migration)
  • Both schema.ts and migration in same commit

sentry의 다른 스킬

generate-frontend-forms
sentry
Sentry의 새로운 폼 시스템을 사용하여 폼을 생성하는 가이드입니다. 폼, 폼 필드, 유효성 검사 또는 자동 저장 기능을 구현할 때 사용하세요.
official
sentry-snapshots-cocoa
sentry
Apple/Cocoa 프로젝트를 위한 전체 Sentry Snapshots 설정입니다. "SnapshotPreviews 설정", "Apple 스냅샷 테스트 설정", "Apple 스냅샷 업로드" 요청 시 사용하세요.
official
architecture-review
sentry
직원 수준의 코드베이스 건강 검토. 모놀리식 모듈, 무음 실패, 타입 안전성 격차, 테스트 커버리지 구멍, LLM 친화성 문제를 찾습니다.
official
linear-type-labeler
sentry
Linear 이슈를 분류하고, 각 이슈의 제목과 설명 내용을 기반으로 Sentry 워크스페이스의 레이블 분류 체계에서 Type 레이블을 적용합니다.
official
sentry-flutter-sdk
sentry
Flutter 및 Dart를 위한 완전한 Sentry SDK 설정입니다. "Flutter에 Sentry 추가", "sentry_flutter 설치", "Dart에서 Sentry 설정" 또는 오류 구성을 요청받았을 때 사용하세요.
official
sentry-svelte-sdk
sentry
Svelte 및 SvelteKit을 위한 완전한 Sentry SDK 설정입니다. "Svelte에 Sentry 추가", "SvelteKit에 Sentry 추가", "@sentry/sveltekit 설치" 또는 구성 요청 시 사용하세요.
official
vercel-react-best-practices
sentry
Vercel Engineering의 React 및 Next.js 성능 최적화 가이드라인입니다. 이 스킬은 React/Next.js 코드를 작성, 검토 또는 리팩토링할 때 사용해야 합니다.
official
sentry-tanstack-start-sdk
sentry
TanStack Start React용 전체 Sentry SDK 설정. "TanStack Start에 Sentry 추가", "@sentry/tanstackstart-react 설치" 또는 오류 구성 요청 시 사용…
official