talk / backend /sql /034_music_themes.sql
user
Deploy StyleVoiceChat backend
aa9892b
Raw History Blame Contribute Delete
3.27 kB
-- ์นดํŽ˜ 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.';