talk / backend /sql /007_user_laugh_cache.sql
user
Deploy StyleVoiceChat backend
aa9892b
Raw History Blame Contribute Delete
2.24 kB
-- Phase 2 (laugh register): μ‚¬μš©μžλ³„ λ³€ν™˜λœ μ›ƒμŒ wav μΊμ‹œ.
--
-- μ‚¬μš©μžκ°€ μŒμ„± μ„€μ •μ—μ„œ apply_dual 호좜 μ‹œ λ°±κ·ΈλΌμš΄λ“œ μž‘μ—…μ΄ λͺ¨λ“  active
-- admin μ›ƒμŒ ν…œν”Œλ¦Ώμ„ μ‚¬μš©μž ref μŒμƒ‰μœΌλ‘œ λ³€ν™˜ β†’ κ²°κ³Ό wav λ₯Ό storage 에 μ €μž₯.
-- μ±„νŒ… chunker (Phase 3) κ°€ μ›ƒμŒ 토큰 감지 μ‹œ 이 μΊμ‹œμ—μ„œ wav url 쑰회.
--
-- ν‚€: (user_id, voice_storage_path, template_id) β€” ν•œ μ‚¬μš©μžμ˜ 같은 μŒμ„± ref
-- + 같은 ν…œν”Œλ¦Ώ μ‘°ν•©λ‹Ή 1ν–‰. 같은 μŒμ„±μ΄λ©΄ voice_storage_path λ™μΌν•˜λ―€λ‘œ dual
-- register (casual/formal) μ–‘μͺ½μ΄ 곡유.
CREATE TABLE IF NOT EXISTS public.user_laugh_cache (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
voice_storage_path TEXT NOT NULL, -- μ‚¬μš©μž ref wav 의 storage_path
template_id UUID NOT NULL REFERENCES public.admin_laugh_templates(id) ON DELETE CASCADE,
laugh_storage_path TEXT NOT NULL, -- λ³€ν™˜λœ wav 의 storage_path (voice-clones 버킷)
ready BOOLEAN NOT NULL DEFAULT FALSE, -- λ³€ν™˜ 성곡 = TRUE
error TEXT, -- λ³€ν™˜ μ‹€νŒ¨ μ‹œ λ©”μ‹œμ§€ (~500 chars truncate)
duration_sec REAL, -- λ³€ν™˜λœ wav 의 μž¬μƒ μ‹œκ°„
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
UNIQUE (user_id, voice_storage_path, template_id)
);
CREATE INDEX IF NOT EXISTS user_laugh_cache_user_voice_idx
ON public.user_laugh_cache (user_id, voice_storage_path)
WHERE ready = TRUE;
ALTER TABLE public.user_laugh_cache ENABLE ROW LEVEL SECURITY;
-- μ •μ±… μ—†μŒ: service_role 만 μ ‘κ·Ό. ν”„λ‘ νŠΈλŠ” λ°±μ—”λ“œ API ν†΅ν•΄μ„œ 쑰회.
COMMENT ON TABLE public.user_laugh_cache IS
'Phase 2 (laugh register): μ‚¬μš©μž ref Γ— admin ν…œν”Œλ¦Ώ λ³€ν™˜ μΊμ‹œ. apply_dual 직후 λ°±κ·ΈλΌμš΄λ“œ VC μž‘μ—…μ΄ 채움.';
COMMENT ON COLUMN public.user_laugh_cache.voice_storage_path IS
'μ‚¬μš©μž ref wav 의 storage_path (예: {user_id}/{stem}.wav). dual register 의 casual/formal μ–‘μͺ½μ΄ 같은 path 곡유.';
COMMENT ON COLUMN public.user_laugh_cache.laugh_storage_path IS
'λ³€ν™˜λœ wav (예: {user_id}/laughs/{stem}_{template_id}.wav).';