Spaces:
Sleeping
Sleeping
File size: 3,380 Bytes
aa9892b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | -- μΉ΄ν BGM μ°μμ¬μ νμλΌμΈ (2026-05-20, BGM Phase 2).
--
-- μ μ£Όκ° [μ°μ»΄ λ©νΈ TTS] β [BGM] β [μ λ©λ΄ λ©νΈ TTS] β [BGM] ... λ₯Ό μμλλ‘ μ‘°ν©.
-- κΈ°μ‘΄ playlists(sql/013, μμ½λ°©μ‘ μ μ©)μ λ³κ° β BGM μ μ© μ κ· ν
μ΄λΈ.
--
-- ν΅μ¬ μμΉ(μ¬μ κ²½λ‘ GPU 0):
-- - bgm μ¬λ‘― = music_themes(κΈλ‘λ²) λλ user_music(Phase 4) μ°Έμ‘° β Storage νμΌ.
-- - tts_ment μ¬λ‘― = λ©νΈ ν
μ€νΈλ₯Ό **μ¬μ μμ±**(νμλΌμΈ μ μ₯/νΈμ§ μ TTS 1ν) β
-- ment_audio_path μ μ μ₯. μ¬μ μμ μ΄ νμΌλ§ μλΉ (μ€μκ° TTS μλ).
-- ment_status: pending(μμ± λκΈ°) β ready(νμΌ μμ) β failed(μ¬μλ λμ).
--
-- νκ· 0: μ κ· ν
μ΄λΈ β κΈ°μ‘΄ TTS/voice/playlist/care/music_themes μν₯ μμ.
-- RLS: μμ μλ§ read/write (λ°©μ΄). λ°±μλλ service_role + user_id νν° λ³ν.
CREATE TABLE IF NOT EXISTS public.music_timelines (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
user_id uuid NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
name text NOT NULL DEFAULT 'λ΄ μΉ΄ν BGM',
is_active boolean NOT NULL DEFAULT true,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
);
CREATE TABLE IF NOT EXISTS public.timeline_items (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
timeline_id uuid NOT NULL REFERENCES public.music_timelines(id) ON DELETE CASCADE,
position integer NOT NULL, -- μ¬μ μμ (0-based)
item_type text NOT NULL CHECK (item_type IN ('bgm', 'tts_ment')),
-- bgm μ¬λ‘―
music_theme_id uuid REFERENCES public.music_themes(id) ON DELETE SET NULL,
-- tts_ment μ¬λ‘― (μ¬μ μμ± β νμΌ μ¬μ)
ment_text text,
ment_voice text, -- μμ/μ€νΌμ»€ ν€
ment_audio_path text, -- μμ±λ λ©νΈ μ€λμ€ ('music' λ²ν· μλ κ²½λ‘)
ment_status text NOT NULL DEFAULT 'pending'
CHECK (ment_status IN ('pending', 'ready', 'failed')),
settings jsonb NOT NULL DEFAULT '{}', -- loop/gap/volume λ± μ¬λ‘―λ³ μ΅μ
created_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS timeline_items_timeline_pos_idx
ON public.timeline_items (timeline_id, position);
CREATE INDEX IF NOT EXISTS music_timelines_user_idx
ON public.music_timelines (user_id, updated_at DESC);
ALTER TABLE public.music_timelines ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.timeline_items ENABLE ROW LEVEL SECURITY;
-- μμ μλ§ μ κ·Ό (λ°±μλ service_role μ RLS bypass β μΆκ° λ°©μ΄μ ).
DROP POLICY IF EXISTS music_timelines_owner ON public.music_timelines;
CREATE POLICY music_timelines_owner ON public.music_timelines
FOR ALL USING (user_id = auth.uid()) WITH CHECK (user_id = auth.uid());
DROP POLICY IF EXISTS timeline_items_owner ON public.timeline_items;
CREATE POLICY timeline_items_owner ON public.timeline_items
FOR ALL USING (
EXISTS (SELECT 1 FROM public.music_timelines t
WHERE t.id = timeline_items.timeline_id AND t.user_id = auth.uid())
);
COMMENT ON TABLE public.music_timelines IS
'μΉ΄ν BGM μ°μμ¬μ νμλΌμΈ (λ©νΈ TTS + BGM). μ¬μ=Storage νμΌ μλΉ.';
|