Claude Code로 데이터베이스 설계를 효율화하는 7가지 실전 기법
ER 다이어그램 설계부터 스키마 생성, 마이그레이션, 인덱스 최적화까지.
Database design involves table structures, relations, indexes, and migrations. With Claude Code, you can go from design brainstorming to implementation in one flow.
1. Generate Table Design from Requirements
Describe requirements in plain language and get a schema back.
claude -p "
Design a database for an e-commerce site.
Requirements:
- Users (email, password hash, profile)
- Products (name, description, price, stock, category)
- Orders (link users to products, quantity, status)
- Reviews (users post reviews on products)
- Categories (hierarchical)
Output as a Prisma schema with appropriate indexes.
"
A normalized schema returns in seconds.
2. Analyze Existing Database Schemas
Understand legacy database structures.
npx prisma db pull
claude -p "
Read prisma/schema.prisma and explain:
- Main tables and their roles
- Relationships between tables
- Design issues (normalization gaps, missing indexes)
- Improvement suggestions
"
3. Auto-Generate Migrations
Let Claude Code handle migration files for schema changes.
claude -p "
Add these columns to the users table:
- phone_number (string, nullable, unique)
- avatar_url (string, nullable)
- last_login_at (datetime, nullable)
Update the Prisma schema and run npx prisma migrate dev.
Migration name: add-user-profile-fields
"
Schema change to migration execution, end to end. See DB Migration Automation.
4. Optimize Indexes
Identify slow queries and get index recommendations.
claude -p "
Read prisma/schema.prisma and optimize indexes:
1. Columns frequently used in WHERE clauses
2. Columns used in JOIN conditions
3. Composite indexes for ORDER BY columns
4. Unused indexes to remove
Output the improved schema.
"
5. Auto-Generate Seed Data
Create realistic test data for development.
claude -p "
Create prisma/seed.ts with:
- 10 users with realistic names and emails
- 5 categories (Electronics, Books, Food, Clothing, Sports)
- 10 products per category with realistic names and prices
- 3-5 orders per user
- 1-3 reviews per product
Use faker.js for random generation.
Also configure prisma.seed in package.json.
"
6. Generate Query Helpers
Auto-generate repository pattern helpers.
claude -p "
Create repository classes in src/repositories/:
ProductRepository:
- findAll(filters, pagination, sort)
- findById(id) - include related category and reviews
- search(keyword) - full-text search
- findByCategory(categoryId, pagination)
- getPopular(limit) - sorted by review count
Use Prisma. Avoid N+1 queries.
"
7. Auto-Generate ER Diagrams
Generate text-based ER diagrams.
claude -p "
Read prisma/schema.prisma and generate a Mermaid ER diagram.
Show relationships (1:N, N:N) with arrows.
"
Output example:
erDiagram
User ||--o{ Order : places
User ||--o{ Review : writes
Order ||--|{ OrderItem : contains
Product ||--o{ OrderItem : "ordered in"
Product ||--o{ Review : receives
Category ||--o{ Product : categorizes
Gotchas
Don’t Over-Normalize
Claude Code tends to normalize aggressively. In practice, intentional denormalization for performance is common. Note it in CLAUDE.md.
Always Review Migrations
Review auto-generated migrations before running. Especially changes that delete data.
Never Connect to Production
When passing DATABASE_URL, use local or staging. Add “never connect to production DB” to CLAUDE.md.
Conclusion
- Auto-generate table designs from requirements
- Analyze and improve legacy DB structures
- Automate migrations end to end
- Get index optimization recommendations
- Auto-generate realistic seed data
- Generate repository pattern query helpers
- Output ER diagrams in Mermaid format
Claude Code as your DB design partner boosts both design quality and dev speed. See Prisma ORM Guide. Official docs at Anthropic Claude Code.
Claude Code 워크플로우를 한 단계 업그레이드하세요
지금 바로 Claude Code에 복사해 쓸 수 있는 검증된 프롬프트 템플릿 50선.
무료 PDF: 5분 완성 Claude Code 치트시트
이메일 주소만 등록하시면 A4 한 장짜리 치트시트 PDF를 즉시 보내드립니다.
개인정보는 엄격하게 관리하며 스팸은 보내지 않습니다.
이 글을 작성한 사람
Masa
Claude Code를 적극 활용하는 엔지니어. 10개 언어, 2,000페이지 이상의 테크 미디어 claudecode-lab.com을 운영 중.
관련 글
Claude Code × AWS Lambda 완전 가이드 | 함수 생성부터 배포 자동화까지
Claude Code로 AWS Lambda 함수를 초고속 개발. 핸들러 생성, IAM 정책 설계, SAM 배포 자동화까지 API Gateway/S3/DynamoDB 연동 실전 코드로 완전 해설.
Claude Code로 신규 엔지니어 온보딩 시간을 대폭 단축하는 방법
3개월 램프업을 2주로. Claude Code를 신입의 코드베이스·환경·첫 PR 코파일럿으로 활용하세요.
Claude Code로 기술 부채를 시각화하고 체계적으로 줄이는 방법
갚지 않은 기술 부채는 엔지니어링 속도를 갉아먹습니다. Claude Code로 부채를 드러내고, 우선순위를 정하고, 점진적으로 상환하는 법을 배워보세요.