Repository navigation
feat: Supabase 연결부 및 환경별 스키마 분리 추가 - #22
Conversation
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthrough다환경(develop/production) 지원을 위해 데이터베이스 스키마 분리 로직을 도입합니다. Changes데이터베이스 다환경 스키마 분리
Sequence DiagramsequenceDiagram
participant Deployment as 배포 프로세스
participant InitScript as db-schema-init
participant Database as PostgreSQL
participant Drizzle as Drizzle-Kit
participant Runtime as 런타임<br/>DatabaseService
Deployment->>InitScript: DATABASE_URL, DATABASE_SCHEMA
InitScript->>Database: CREATE SCHEMA IF NOT EXISTS {schema}
Database-->>InitScript: 스키마 생성 완료
Deployment->>Drizzle: db:migrate<br/>(search_path={schema})
Drizzle->>Database: 마이그레이션 적용
Database-->>Drizzle: 마이그레이션 완료
Deployment->>Runtime: ConfigService
Runtime->>Database: search_path={schema}로<br/>연결 설정
Database-->>Runtime: 연결 완료
Runtime->>Runtime: 스키마 격리 상태 유지
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
DB 연결부를 레이어 컨벤션에 맞춰 src/database → src/infrastructures/db로 옮기고, import 경로(app.module, health indicator + spec)를 갱신합니다. 중앙 schema 플레이스홀더는 제거하고 drizzle 스키마 소스를 모듈별 *.schema.ts로 전환합니다. 동작 변경은 없습니다. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
하나의 Supabase 인스턴스 안에서 Postgres 스키마로 환경을 가릅니다. - db.env.ts: resolveDbSchema() — DATABASE_SCHEMA만으로 스키마 결정 (NODE_ENV 비의존, 미설정 시 안전한 기본값 develop) - drizzle.config: 테이블 DDL은 스키마명 없이 생성하고 search_path로 대상 스키마 지정, __drizzle_migrations 기록을 환경 스키마별로 분리. 마이그레이션은 세션 풀러(DATABASE_URL_DIRECT, 5432) 필수 — 미설정 시 에러. - scripts/db-schema-init.ts: 환경 스키마 사전 생성(CREATE SCHEMA) - env.schema: DATABASE_SCHEMA / DATABASE_URL_DIRECT 추가, DB_POOL_SIZE 기본 5 - package.json: db:schema-init / db:studio 추가, db:push 제거 (versioned generate/migrate와 섞이면 마이그레이션 기록이 꼬임) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- prepare: false (6543 트랜잭션 풀러는 prepared statement 미지원) - connection.search_path: 환경 스키마 고정 (DATABASE_SCHEMA 기반) - casing: snake_case (drizzle 인스턴스) - DB_POOL_SIZE 기본값 5 TLS는 연결 문자열의 sslmode로 제어하므로 로컬 postgres는 영향 없음. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
8f40206 to
8261254
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@scripts/db-schema-init.ts`:
- Line 37: The top-level call to main() should explicitly handle promise
rejections: wrap the call to main() with a rejection handler (e.g.,
main().catch(err => { console.error("Failed to initialize DB schema:", err);
process.exit(1); })) or replace it with an immediately-invoked async wrapper
that catches errors and exits with a non-zero code; update the invocation of
main() so any thrown/rejected error is logged via console/process logger and the
process exits with code 1.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 58f112cc-c2de-4f82-af76-f35994018e26
📒 Files selected for processing (13)
.env.exampledrizzle.config.tspackage.jsonscripts/db-schema-init.tssrc/app.module.tssrc/config/env.schema.tssrc/database/database.service.tssrc/database/schema/index.tssrc/health/drizzle.health-indicator.spec.tssrc/health/drizzle.health-indicator.tssrc/infrastructures/db/database.module.tssrc/infrastructures/db/database.service.tssrc/infrastructures/db/db.env.ts
💤 Files with no reviewable changes (2)
- src/database/database.service.ts
- src/database/schema/index.ts
sudosubin
left a comment
There was a problem hiding this comment.
저희는 Cloud Run 환경이긴 하지만 서버리스/Edge 환경인 것은 아니어서 Pooler transaction mode 보다는 Pooler session mode이 더 좋다는 생각이 들었어요. 그리고 Pooler를 사용하면 약간의 레이턴시가 더 증가하기도 해서 Direct connection을 그냥 사용해보면 더 좋을 것 같아요.
(ipv6 이슈로 연결이 불가하면 그 때 Pooler session mode를 테스트해봐도 될 것 같아요)
sudosubin 리뷰 반영: Cloud Run은 상주 서버라 트랜잭션 풀러 대신 Direct connection(또는 session pooler)이 적합. 이에 맞춰: - DatabaseService: prepare:false 제거(트랜잭션 풀러 전용 → prepared statement 복구) - DATABASE_URL_DIRECT 제거, 런타임·마이그레이션 모두 단일 DATABASE_URL 사용 - drizzle.config / db-schema-init: DATABASE_URL 기준으로 정리 - .env.example: Direct connection 우선, IPv6 불가 시 session pooler 폴백 안내 CodeRabbit 반영: db-schema-init main()에 rejection 핸들러 추가. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…paration # Conflicts: # package.json
📌 Related Issue
GM-2
브랜치명은 다음 테스크부터 신경쓸게요!
🚀 Description
서버가 Supabase(PostgreSQL)에 붙는 연결부를 추가하고, 하나의 Supabase 안에서 Postgres 스키마로 환경(develop/production)을 분리합니다.
기존 main(PR #2)에 이미 들어와 있던 DB 연결부와 충돌하지 않도록, 새로 만들지 않고 기존
DatabaseService에 합치는 방향으로 정리했습니다.🔧 Supabase 연결 옵션
Supabase는 DB 앞에 연결을 모아 나눠 쓰게 해주는 커넥션 풀러를 둡니다. 포트에 따라 동작이 다릅니다.
DATABASE_URLDATABASE_URL_DIRECTprepare: false— 6543은 연결이 계속 바뀌어 prepared statement를 못 쓰므로 끔.?sslmode=require로 제어. (로컬 postgres는 미지정 → 로컬/테스트 안 깨짐)connection.search_path— 접속 시 바라볼 스키마를 고정해 환경 격리.DATABASE_URL_DIRECT미설정 시 에러로 막습니다(폴백 안 함).🗂 환경 분리 (스키마 기반)
DATABASE_SCHEMA하나(NODE_ENV에 의존하지 않음). 미설정 시 안전한 기본값develop, 운영에서만production주입.search_path로 대상 스키마 결정.__drizzle_migrations)은 환경 스키마별로 분리 → dev/prod가 기록을 공유해 한쪽만 반영되는 문제 방지.✅ 기존 main 대비 변경점
src/database/→src/infrastructures/db/로 이전 (레이어 컨벤션)process.env직접 읽기 대신ConfigService(valibot 검증) 경유로 통일DB_POOL_SIZE(기본 10→5) 유지,DATABASE_SCHEMA·DATABASE_URL_DIRECT추가DatabaseService에 Supabase 풀러 연결 옵션 적용src/modules/**/*.schema.tsdb:push제거(versionedgenerate/migrate와 섞이면 마이그레이션 기록이 꼬임),db:schema-init·db:studio추가🧪 마이그레이션 워크플로
🔭 후속 작업 (별도 PR)
DATABASE_URL(_DIRECT)이 외부에서 주입된다고 가정합니다.🧷 테스트
로컬 Postgres로 검증 완료:
bun run db:schema-init→ 5432 연결 +develop스키마 생성 확인ConfigModule→DatabaseService→health) →database: up+ graceful shutdown 확인search_path/current_schema=develop라우팅 확인bun run test/ health indicator 단위 테스트 통과Summary by CodeRabbit
릴리스 노트
새로운 기능
변경사항
DATABASE_SCHEMA환경 변수 추가(미설정 시develop, 허용값develop|production)db:push제거,db:schema-init/db:studio추가)테스트