Skip to content

chore: Supabase 스키마 구축 및 DB 타입 시스템 셋업 (#30) - #32

Merged
wjswlgh96 merged 2 commits into
developfrom
chore/#30/supabase-schema
Jul 9, 2026
Merged

chore: Supabase 스키마 구축 및 DB 타입 시스템 셋업 (#30)#32
wjswlgh96 merged 2 commits into
developfrom
chore/#30/supabase-schema

Conversation

@wjswlgh96

@wjswlgh96 wjswlgh96 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Pull Request

작업 내용

  • 확정 ERD 기반 Supabase 스키마 적용분(마이그레이션 4건)을 레포에 동기화
  • DB 타입 자동 생성 환경 셋업database.types.ts(자동 생성) + supabase.types.ts(Generic 헬퍼) + npm run gen:types
  • workspace 도메인 DB 타입 정의 (workspace.db.types.ts) — 다른 도메인이 따라갈 기준 구현
  • Supabase 컨벤션 문서 추가 (docs/conventions/supabase-convention.md)

작업 결과

  • Supabase syncly 프로젝트(teamplerun org)에 적용 완료된 스키마가 레포와 일치:
    • ENUM 7종 (전부 네이티브 ENUM + snake_case): workspace_purpose / task_status / task_priority / task_category / resource_type / calendar_event_type / member_role
    • 테이블 14개 (ERD 13 + sprints) + updated_at 자동 갱신 트리거 + FK 인덱스
    • RLS: auth.uid() 기반 실 정책 전 테이블 작성 완료 (Security Definer 헬퍼 is_workspace_member/is_workspace_owner). 현재는 dev_full_access 임시 정책이 공존해 전체 허용 — auth 연동 시 dev 정책만 drop하면 발동
    • 제약: 닉네임 unique, 멤버 복합 FK 2건, profiles(email) unique, CHECK 3건
  • 테스트 시드 (id 끝자리로 식별):
    • 계정 5개: test1@test.com ~ test5@test.com / test1234! — 실제 로그인 가능한 auth 계정
    • 워크스페이스 3개: ...1001 캡스톤 디자인 팀(team_project) · ...1002 Fitto 앱 개발팀(side_project) · ...1003 카페 그레이 운영(store_operation), 5명 전원 멤버
    • 도메인 데이터: tasks 21(스프린트 2개 + 백로그) · 공지 4 · 회의록 3 · 자료 4 · 일정 6 · 채팅 4 · 근무표 35 · 레이아웃 샘플 1
  • get_my_workspaces 형태 집계, 벨로시티(스프린트별 포인트 합계) 집계 쿼리 동작 검증 완료

변경 사항

Added

  • supabase/migrations/ — 4건, 원격 schema_migrations 버전과 파일명 일치
    • create_enums_and_core_tables / seed_test_users_and_data / add_auth_rls_policies / add_constraints
  • src/shared/model/database.types.ts — 자동 생성 DB 타입 (직접 수정·직접 import 금지)
  • src/shared/model/supabase.types.ts — Generic 헬퍼 6종 (GenericTables / Insert / Update / GenericEnums / GenericFunctionArgs / GenericFunctionReturns)
  • src/entities/workspace/model/workspace.db.types.ts — workspace 도메인 DB 타입 (기준 구현)
  • docs/conventions/supabase-convention.md — 타입 사용 규칙 · 쓰기 경로(RPC vs 직접 쿼리) · ENUM · 마이그레이션 · 테스트 시드 정리
  • package.jsongen:types 스크립트 (npx supabase gen types typescript ...)

Changed

  • entities/workspace Public API에 DB 타입 export 추가
  • .prettierignore — 자동 생성 파일(database.types.tssupabase/migrations 제외

Fixed

  • (없음)

실행화면

  • 백엔드/툴링 작업으로 화면 변경 없음. 시드 데이터는 Supabase 대시보드 Table Editor에서 확인 가능합니다.

테스트

  • 로컬 실행 확인 (lint / typecheck / 신규 파일 format:check 통과)
  • 주요 시나리오 확인 (내 워크스페이스 집계 · 벨로시티 집계 SQL 검증, 마이그레이션 4건 원격 적용 성공)
  • 영향 범위 확인 (기존 프론트 코드는 mock 그대로 동작 — DB 연동은 각 도메인이 준비되는 대로 교체)

리뷰 체크리스트

  • PR base branch가 올바릅니다. (feature/* -> develop, 배포 시 develop 또는 release/* -> main)
  • 브랜치명이 Type/#issue-number/description 형식을 따릅니다.
  • 커밋 메시지가 컨벤션을 따릅니다.
  • 불필요한 console.log, 주석, 임시 코드를 제거했습니다.
  • 타입 에러와 린트 에러를 확인했습니다.
  • CodeRabbit 1차 리뷰를 확인했습니다.
  • CodeRabbit 리뷰 반영 후 Discord에 공유했습니다.
  • 최소 1명 이상의 approve 후 merge합니다.

리뷰 요청사항

  • RPC 개발 규칙: auth 연동 전까지 RPC는 p_user_id uuid 파라미터로 유저를 받습니다 (auth.uid()는 세션이 없어 null). 테스트는 시드 계정 id(00000000-...-0001 등) 사용 → auth 연동 후 일괄 교체 예정입니다.
  • 쓰기 경로 컨벤션 확인 부탁드립니다: 여러 테이블 트랜잭션 쓰기 = RPC / 단일 테이블 upsert·부분 update = 직접 쿼리 (자세한 건 docs/conventions/supabase-convention.md)
  • work_schedule_entries는 ERD안(날짜식 work_date)대로 생성했습니다. 요일 반복식으로 확정되면 ALTER 1회로 전환 예정 (스케줄 담당자분 확인 부탁드려요)
  • 각 도메인 DB 타입은 entities/<도메인>/model/<도메인>.db.types.ts 패턴으로 만들어 쓰시면 됩니다 (workspace 참고)

관련 이슈

Closes #30

Summary by CodeRabbit

  • New Features
    • Supabase 타입 생성 스크립트와 워크스페이스 관련 타입이 추가되어 데이터 연동이 더 안정적으로 준비되었습니다.
    • 새로운 DB 스키마, 도메인 ENUM, 테스트 시드 데이터, RLS 기반 접근 제어가 적용되었습니다.
  • Documentation
    • Supabase 연동 규칙 및 타입/마이그레이션 갱신 절차 가이드가 추가되었습니다.
  • Bug Fixes
    • 중복 및 무결성 제약, 입력 값 검증이 강화되었습니다.
  • Chores
    • 자동 포맷팅 제외 경로를 정리했습니다.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Supabase 스키마, RLS, 시드 데이터를 마이그레이션으로 동기화했고, 생성된 DB 타입과 제네릭 헬퍼를 추가했다. workspace 도메인 DB 타입 export를 정리했으며, 타입 생성 스크립트, ignore 설정, 컨벤션 문서도 함께 반영했다.

Changes

Supabase 스키마 및 타입 생성

Layer / File(s) Summary
핵심 스키마 생성
supabase/migrations/20260709025327_create_enums_and_core_tables.sql
ENUM 타입, 핵심 테이블, 인덱스, updated_at 트리거, 임시 permissive RLS 정책이 추가된다.
제약조건 추가
supabase/migrations/20260709032015_add_constraints.sql
복합 UNIQUE, 외래키 CASCADE, 이메일 UNIQUE, 날짜·시간·포인트 CHECK 제약이 추가된다.
테스트 시드 데이터
supabase/migrations/20260709025457_seed_test_users_and_data.sql
테스트 계정, 워크스페이스, 멤버십, 모듈, 스프린트, 태스크, 공지, 회의록, 자료, 일정, 채팅, 근무 스케줄, 대시보드 레이아웃 시드가 삽입된다.
RLS 정책 정의
supabase/migrations/20260709025820_add_auth_rls_policies.sql
멤버/오너 판정 함수와 테이블별 RLS 정책, 동적 멤버십 정책이 추가된다.
RLS 헬퍼 스키마 이동
supabase/migrations/20260709034833_move_rls_helpers_to_private_schema.sql
RLS 헬퍼 함수가 private 스키마로 이동되고, 실행 권한과 제한이 재설정된다.
DB 타입 생성과 제네릭 헬퍼
src/shared/model/database.types.ts, src/shared/model/supabase.types.ts, package.json, .prettierignore, docs/conventions/supabase-convention.md
생성된 Supabase DB 타입, 제네릭 헬퍼, gen:types 스크립트, ignore 설정, 컨벤션 문서가 추가된다.
Workspace DB 타입 export
src/entities/workspace/model/workspace.db.types.ts, src/entities/workspace/index.ts
workspace 도메인 DB 타입이 파생되고 public export가 정리된다.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

  • TeampleRun/syncly#10: src/entities/workspace/index.ts의 workspace 퍼블릭 API export 구성을 함께 다룬다.
  • TeampleRun/syncly#16: workspace purpose 관련 타입을 동일한 public API 경로에서 노출하는 변경과 맞닿아 있다.

Suggested reviewers: Kwon812, 0011810, seongjinss555

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed 제목은 Supabase 스키마 구축과 DB 타입 셋업이라는 핵심 변경을 정확히 요약합니다.
Description check ✅ Passed 요구 템플릿의 주요 섹션과 정보가 모두 채워져 있어 검토용 설명으로 충분합니다.
Linked Issues check ✅ Passed ERD 동기화, 마이그레이션 반영, gen:types 추가, 제약/시드/RLS까지 링크 이슈의 핵심 요구를 충족합니다.
Out of Scope Changes check ✅ Passed 추가된 문서, ignore 규칙, 타입 헬퍼와 RLS 헬퍼 이동은 모두 Supabase 스키마/타입 셋업 범위에 속합니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/#30/supabase-schema

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 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 `@src/shared/model/database.types.ts`:
- Around line 704-710: `database.types.ts`의 `Functions` 타입이 실제 RPC 목록과 불일치합니다.
`is_workspace_member`/`is_workspace_owner`만 두지 말고, `create_workspace`와
`get_my_workspaces`를 `Functions`에 추가해 `src/shared/model/database.types.ts`를 최신
스키마에 맞추세요. `create_workspace`와 `get_my_workspaces`를 참조하는 `workspace` API 주석과 타입
생성 결과가 서로 일치하는지 함께 확인해 정리하세요.

In `@supabase/migrations/20260709025327_create_enums_and_core_tables.sql`:
- Line 45: `setup_status` is currently defined as free-form text, unlike the
other status/domain fields, so it can store invalid values. Update the
enum/table definition in the migration that creates the core tables to constrain
`setup_status` the same way as `task_status` and `resource_type`—prefer a
dedicated ENUM or, if that is not feasible, add a CHECK constraint. Also make
sure the corresponding constraints in `add_constraints.sql` are updated so the
`setup_status` values are validated consistently.
🪄 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 Plus

Run ID: 8c34b5ba-8ce1-4d2a-85d7-c36d433d48d1

📥 Commits

Reviewing files that changed from the base of the PR and between 2672f79 and aeaca4f.

📒 Files selected for processing (11)
  • .prettierignore
  • docs/conventions/supabase-convention.md
  • package.json
  • src/entities/workspace/index.ts
  • src/entities/workspace/model/workspace.db.types.ts
  • src/shared/model/database.types.ts
  • src/shared/model/supabase.types.ts
  • supabase/migrations/20260709025327_create_enums_and_core_tables.sql
  • supabase/migrations/20260709025457_seed_test_users_and_data.sql
  • supabase/migrations/20260709025820_add_auth_rls_policies.sql
  • supabase/migrations/20260709032015_add_constraints.sql

Comment thread src/shared/model/database.types.ts
Comment thread supabase/migrations/20260709025327_create_enums_and_core_tables.sql

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 `@supabase/migrations/20260709034833_move_rls_helpers_to_private_schema.sql`:
- Around line 12-18: The migration in the private-schema RLS helper setup should
explicitly remove schema access for anon/public in addition to function execute
grants. Update the `private.is_workspace_member` and
`private.is_workspace_owner` permission block to also revoke `USAGE` on the
`private` schema from `anon` and `public`, keeping the existing `grant
usage`/`grant execute` for `authenticated` intact.
🪄 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 Plus

Run ID: 95b3ed7d-ceb6-4d30-9446-34251c9b3647

📥 Commits

Reviewing files that changed from the base of the PR and between aeaca4f and c4e398b.

📒 Files selected for processing (2)
  • src/shared/model/database.types.ts
  • supabase/migrations/20260709034833_move_rls_helpers_to_private_schema.sql

@seongjinss555 seongjinss555 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore: Supabase 스키마 구축 및 DB 타입 생성 환경 셋업

2 participants