-- 카페 BGM 글로벌 라이브러리 테이블 (2026-05-20, BGM 서비스 Phase 1). -- -- 우리가 사전 생성한 PRO-free 카페 배경음악 카탈로그. Lyria 2 (Vertex AI) 로 생성 → -- auto-loop (src/bgm/autoloop.py: seamless loop + -16 LUFS) 후처리 → Supabase -- Storage('music' 버킷) 저장 → 이 테이블에 메타데이터 1행. -- -- 재생 경로는 GPU/API 0 — 항상 Storage 파일 서빙 (signed URL). 이 테이블은 카탈로그 -- (목록/무드 필터/검색) 용. 사용자 개인 생성곡은 별도 user_music 테이블(Phase 4). -- -- 회귀 0 가드: -- - 신규 테이블 — 기존 TTS/voice/playlist/care 스키마 영향 0. -- - RLS: 글로벌 카탈로그라 인증 사용자 + anon 읽기 허용(public read). 쓰기는 -- service_role 만 (배치 빌더가 service_role 키 사용) — 기본 deny 로 사용자 쓰기 차단. -- - storage_path 는 'music' 버킷 내 상대 경로만 저장 (버킷명 비포함) — 버킷 이전 대비. -- -- 이행 단계: -- 1) 이 SQL 적용 (Supabase SQL editor 또는 마이그레이션 러너) -- 2) Storage 'music' 버킷 생성 (배치 빌더가 없으면 자동 생성 시도) -- 3) scripts/bgm_library/build_library.py 로 배치 생성 → 행 insert -- 4) (Phase 2+) backend 라우터가 카탈로그 조회 + signed URL 발급 -- -- 참조: project_bgm_service (memory), src/bgm/autoloop.py CREATE TABLE IF NOT EXISTS public.music_themes ( id uuid PRIMARY KEY DEFAULT gen_random_uuid(), title text NOT NULL, genre text NOT NULL DEFAULT '', mood_tags text[] NOT NULL DEFAULT '{}', -- 재현/감사용: 생성 파라미터 박제 (Lyria 2) prompt text NOT NULL DEFAULT '', negative_prompt text NOT NULL DEFAULT '', seed bigint, -- 오디오 자산 storage_path text NOT NULL, -- 'music' 버킷 내 상대 경로 (예: themes/lofi/xxx.mp3) duration_sec real, bpm real, -- auto-loop QC 지표 (라이브러리 품질 추적) lufs real, qc_pop_ratio real, qc_rms_ratio real, qc_passed boolean NOT NULL DEFAULT true, -- 운영 is_active boolean NOT NULL DEFAULT true, created_at timestamptz NOT NULL DEFAULT now() ); -- 무드 필터 조회 (예: mood_tags @> '{lofi}') CREATE INDEX IF NOT EXISTS music_themes_mood_tags_idx ON public.music_themes USING gin (mood_tags); CREATE INDEX IF NOT EXISTS music_themes_active_idx ON public.music_themes (is_active, created_at DESC); -- 동일 (path) 중복 방지 (배치 재실행 idempotency) CREATE UNIQUE INDEX IF NOT EXISTS music_themes_storage_path_key ON public.music_themes (storage_path); ALTER TABLE public.music_themes ENABLE ROW LEVEL SECURITY; -- 글로벌 카탈로그: 활성 행은 누구나 읽기 (재생 경로). 쓰기 정책 없음 = service_role 만. DROP POLICY IF EXISTS music_themes_public_read ON public.music_themes; CREATE POLICY music_themes_public_read ON public.music_themes FOR SELECT USING (is_active = true); COMMENT ON TABLE public.music_themes IS '카페 BGM 글로벌 라이브러리 (Lyria 2 생성 + auto-loop). 재생=Storage signed URL.';