이 가이드는 Supabase 데이터베이스 스키마를 관리하고 마이그레이션하는 방법을 설명합니다.
# Homebrew (macOS)
brew install supabase/tap/supabase
# NPM
npm install -g supabase
# 설치 확인
supabase --version.env.local 파일 생성 (.env.example 참조):
cp .env.example .env.local.env.local에 실제 값 입력:
# Supabase Configuration
SUPABASE_URL=https://ddntzfdetgcobzohimvm.supabase.co
SUPABASE_KEY=your_actual_supabase_anon_key_here
# Slack Bot Configuration
SLACK_BOT_TOKEN=your_actual_bot_token_here
SLACK_SIGNING_SECRET=your_actual_signing_secret_here
SLACK_APP_TOKEN=your_actual_app_token_here주의: .env.local은 gitignore되어 있으므로 안전하게 실제 값을 저장할 수 있습니다.
Shadow는 다음 4개의 주요 테이블을 사용합니다:
CREATE TABLE sessions (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id TEXT,
duration NUMERIC NOT NULL DEFAULT 0,
frame_count INTEGER NOT NULL DEFAULT 0,
event_count INTEGER NOT NULL DEFAULT 0,
status TEXT NOT NULL DEFAULT 'pending',
started_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
completed_at TIMESTAMPTZ,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);용도: shadow-py에서 녹화한 세션의 메타데이터 저장
CREATE TABLE analysis_results (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
session_id UUID NOT NULL REFERENCES sessions(id) ON DELETE CASCADE,
action_type TEXT NOT NULL,
target TEXT NOT NULL,
context TEXT,
description TEXT,
confidence NUMERIC,
timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW(),
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);용도: Claude가 분석한 사용자 행동 저장
CREATE TABLE patterns (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
session_id UUID NOT NULL REFERENCES sessions(id) ON DELETE CASCADE,
pattern_type TEXT NOT NULL DEFAULT 'sequence',
count INTEGER NOT NULL DEFAULT 0,
actions JSONB NOT NULL DEFAULT '[]'::jsonb,
similarity_score NUMERIC,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);용도: 반복 패턴 감지 결과 저장
CREATE TABLE slack_events (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
event_type TEXT NOT NULL,
user_id TEXT,
channel_id TEXT,
payload JSONB NOT NULL,
processed BOOLEAN NOT NULL DEFAULT FALSE,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);용도: Slack Bot 이벤트 및 명령 로그
프로젝트의 Makefile에 다음 명령어가 정의되어 있습니다:
# 로컬 Supabase 시작 (Docker 필요)
make db-start
# 로컬 Supabase 중지
make db-stop
# Supabase 상태 확인 (URL, API Keys 등)
make db-status# 새로운 마이그레이션 파일 생성
make db-migration-new
# 프롬프트에서 마이그레이션 이름 입력
# 또는 인자로 직접 전달
make db-migration-new NAME=add_users_table
# 마이그레이션 목록 확인 (로컬 vs 리모트)
make db-migration-list
# 로컬 DB 초기화 (모든 마이그레이션 재실행)
make db-reset# 프로덕션 DB에 마이그레이션 배포
make db-push
# 프로덕션 DB 스키마 가져오기 (역방향)
make db-pull
# 로컬-프로덕션 차이 확인
make db-diffmake db-migration-new
# Enter migration name: add_user_preferences생성된 파일: supabase/migrations/YYYYMMDDHHMMSS_add_user_preferences.sql
- 주석은 반드시 영문만 사용 (한글 주석 금지)
- Migration 파일 작성 시
cat > file.sql << 'EOF'방식 권장 (Claude Write 도구 대신) - 파일 인코딩: UTF-8 without BOM
-- Add user_preferences table
CREATE TABLE user_preferences (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id TEXT NOT NULL,
preferences JSONB NOT NULL DEFAULT '{}'::jsonb,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
-- Create index
CREATE INDEX user_preferences_user_id_idx ON user_preferences(user_id);
-- Enable RLS
ALTER TABLE user_preferences ENABLE ROW LEVEL SECURITY;
-- RLS Policy
CREATE POLICY "Users can manage their own preferences"
ON user_preferences
FOR ALL
USING (auth.uid()::text = user_id);# 로컬 Supabase 시작
make db-start
# .env.local을 로컬로 변경
SUPABASE_URL=http://127.0.0.1:54321
SUPABASE_KEY=<로컬 anon key>
# 마이그레이션 적용
make db-reset
# Python 앱 실행 및 테스트
uv run python demo.py# .env.local을 프로덕션으로 변경
SUPABASE_URL=https://ddntzfdetgcobzohimvm.supabase.co
SUPABASE_KEY=<프로덕션 anon key>
# 프로덕션에 배포
make db-push# 1. 새 기능 브랜치 생성
git checkout -b feat/add-user-preferences
# 2. 마이그레이션 파일 생성 및 작성
make db-migration-new
# supabase/migrations/xxx_add_user_preferences.sql 편집
# 3. 로컬 테스트 (선택)
make db-start
make db-reset
uv run python demo.py
# 4. 프로덕션 배포
make db-push
# 5. Git 커밋
git add supabase/migrations/
git commit -m "feat: add user preferences table"
git push origin feat/add-user-preferences프로덕션 Supabase를 직접 사용하는 경우:
# 1. 마이그레이션 생성
make db-migration-new
# 2. SQL 작성
vim supabase/migrations/xxx_add_feature.sql
# 3. 바로 프로덕션 배포
make db-push
# 4. Git 커밋
git add . && git commit -m "feat: add feature"# 오류 확인
make db-push
# 로컬-프로덕션 차이 확인
make db-diff
# 프로덕션 스키마 가져오기
make db-pull# 수동으로 마이그레이션 상태 수정
supabase migration repair --status applied <migration_id>잘못된 예시 (구버전):
DEFAULT uuid_generate_v4() -- ❌ 오류 발생올바른 예시 (PostgreSQL 13+):
DEFAULT gen_random_uuid() -- ✅ 정상 작동# Supabase 프로젝트 재연결
supabase link --project-ref ddntzfdetgcobzohimvm
# 상태 확인
make db-status문제: Migration 파일에 한글 주석이 있을 때 인코딩 오류 발생
# ❌ 오류 예시
-- LabeledAction 테이블 생성 # 한글 주석으로 인한 UTF-8 오류해결책:
# 1. 영문 주석으로 변경
-- LabeledAction table (Analysis Layer)
# 2. Bash heredoc으로 파일 작성 (Write 도구 대신)
cat > supabase/migrations/YYYYMMDDHHMMSS_add_table.sql << 'EOF'
-- English comments only
CREATE TABLE example (
id UUID PRIMARY KEY DEFAULT gen_random_uuid()
);
EOF
# 3. 파일 인코딩 확인
file -I supabase/migrations/*.sql
# 출력: text/plain; charset=utf-8- 프로젝트 ID:
ddntzfdetgcobzohimvm - 프로덕션 URL:
https://ddntzfdetgcobzohimvm.supabase.co - 연결 상태: ✅ 연결됨 (
supabase link완료) - 마이그레이션 상태: ✅ 초기 스키마 배포 완료
# 현재 마이그레이션 확인
make db-migration-list출력 예시:
Local | Remote | Time (UTC)
----------------|----------------|---------------------
20260131073844 | 20260131073844 | 2026-01-31 07:38:44