talk / backend /sql /037_user_music.sql
user
Deploy StyleVoiceChat backend
aa9892b
Raw History Blame Contribute Delete
1.95 kB
-- μ‚¬μš©μž 동적 생성 μŒμ•… (2026-05-20, BGM Phase 4).
--
-- μžμœ λŒ€ν™” "재즈 μŠ€νƒ€μΌ 3곑 λ§Œλ“€μ–΄μ€˜" β†’ 비동기 Lyria 생성 β†’ 개인 라이브러리.
-- κΈ€λ‘œλ²Œ μΉ΄νƒˆλ‘œκ·Έ(music_themes)와 λ³„κ°œ β€” μ‚¬μš©μž μ†Œμœ . μž¬μƒ κ²½λ‘œλŠ” λ™μΌν•˜κ²Œ
-- 'music' 버킷 signed URL μ„œλΉ™ (GPU/API 0).
--
-- abuse λ°©μ§€: μ‚¬μš©μžλ³„ 일일 생성 cap (λ°±μ—”λ“œ user_music_service μ—μ„œ created_at 카운트).
-- status: generating(Lyria 호좜 쀑) β†’ ready(파일 있음) β†’ failed(μž¬μ‹œλ„ λŒ€μƒ).
--
-- νšŒκ·€ 0: μ‹ κ·œ ν…Œμ΄λΈ”. RLS owner read/write (λ°±μ—”λ“œ service_role + user_id ν•„ν„° 병행).
CREATE TABLE IF NOT EXISTS public.user_music (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
user_id uuid NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
title text NOT NULL DEFAULT '',
prompt text NOT NULL DEFAULT '',
mood_tags text[] NOT NULL DEFAULT '{}',
seed bigint,
storage_path text, -- 'music' 버킷 μƒλŒ€ 경둜 (ready μ‹œ)
duration_sec real,
bpm real,
lufs real,
status text NOT NULL DEFAULT 'generating'
CHECK (status IN ('generating', 'ready', 'failed')),
error_detail text,
created_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS user_music_user_idx
ON public.user_music (user_id, created_at DESC);
CREATE INDEX IF NOT EXISTS user_music_mood_idx
ON public.user_music USING gin (mood_tags);
ALTER TABLE public.user_music ENABLE ROW LEVEL SECURITY;
DROP POLICY IF EXISTS user_music_owner ON public.user_music;
CREATE POLICY user_music_owner ON public.user_music
FOR ALL USING (user_id = auth.uid()) WITH CHECK (user_id = auth.uid());
COMMENT ON TABLE public.user_music IS
'μ‚¬μš©μž 동적 생성 μŒμ•… (Lyria + auto-loop). 개인 라이브러리. μž¬μƒ=Storage signed URL.';