Spaces:
Sleeping
Sleeping
File size: 3,313 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 67 68 69 70 | -- TTS ์ค์ผ์ผ์์ ์ฌ๋กฏ ํ
์ด๋ธ (Supabase SQL Editor์์ ์คํ)
--
-- ์ฌ์ ๋ฐ๊ธ๋ Cloudflare ํฐ๋ ์ฌ๋กฏ(tts4-tts10) + Vast.ai ์ธ์คํด์ค ๋งคํ.
-- ์ด์์๊ฐ admin ์์ "TTS ์๋ฒ ์ถ๊ฐ" ๋๋ฅด๋ฉด free ์ฌ๋กฏ 1๊ฐ ๊ฐ์ ธ์์
-- Vast.ai ์ ์ ์ธ์คํด์ค ๋ง๋ค๊ณ , ๊ทธ ์ธ์คํด์ค์ ์ฌ๋กฏ์ cloudflared ์๊ฒฉ์ฆ๋ช
์ฃผ์
.
CREATE TABLE IF NOT EXISTS public.tts_scale_instances (
-- Cloudflare ํฐ๋ ์ฌ๋กฏ (์ฌ์ ๋ฐ๊ธ, ์ ๋ ์ ๋ฐ๋)
slot_name TEXT PRIMARY KEY, -- 'tts4', 'tts5', ...
hostname TEXT NOT NULL, -- 'tts4.stylevoicetalk.com'
tunnel_id TEXT NOT NULL, -- Cloudflare tunnel UUID
credentials_json JSONB NOT NULL, -- cloudflared credentials (TunnelID/AccountTag/TunnelSecret)
-- Vast.ai ์ธ์คํด์ค ๋งคํ (ํ ๋น ์ ์ฑ์์ง)
vast_instance_id BIGINT, -- ํ ๋น๋ Vast ์ธ์คํด์ค ID (NULL = free)
vast_offer_id BIGINT, -- ๊ฒ์ ๊ฒฐ๊ณผ ID (์ฐธ์กฐ์ฉ)
vast_dph DECIMAL(8,5), -- $/hour ๋น์ฉ
-- ์ํ ์ถ์
-- 'free' / 'creating' / 'pulling' / 'starting' / 'ready' / 'warm_stopped' / 'destroying' / 'failed'
status TEXT NOT NULL DEFAULT 'free',
status_detail TEXT, -- ์๋ฌ ๋ฉ์์ง ๋ฑ
is_warm BOOLEAN NOT NULL DEFAULT false, -- warm pool ๋ฉค๋ฒ์ธ์ง (stopped ์ํ๋ก ์ ์ง)
assigned_at TIMESTAMPTZ, -- Vast ์ธ์คํด์ค ์์ฑ ์๊ฐ
became_ready_at TIMESTAMPTZ, -- /health 200 ๋๋ฌ ์๊ฐ
released_at TIMESTAMPTZ, -- destroy ์๋ฃ ์๊ฐ
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
-- ๋น ์ฌ๋กฏ ๋น ๋ฅด๊ฒ ์ฐพ๊ธฐ
CREATE INDEX IF NOT EXISTS idx_tts_scale_status ON public.tts_scale_instances(status)
WHERE status IN ('free', 'warm_stopped');
-- updated_at ์๋ ๊ฐฑ์ ํธ๋ฆฌ๊ฑฐ
CREATE OR REPLACE FUNCTION public.set_updated_at_tts_scale()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
DROP TRIGGER IF EXISTS trg_tts_scale_updated_at ON public.tts_scale_instances;
CREATE TRIGGER trg_tts_scale_updated_at
BEFORE UPDATE ON public.tts_scale_instances
FOR EACH ROW EXECUTE FUNCTION public.set_updated_at_tts_scale();
-- RLS: service_role ๋ง ์ ๊ทผ (๊ด๋ฆฌ์ ์ ์ฉ ํ
์ด๋ธ)
ALTER TABLE public.tts_scale_instances ENABLE ROW LEVEL SECURITY;
-- (์ ์ฑ
์ถ๊ฐ ์ ํจ โ service_role ์ RLS ์ฐํ. ์ผ๋ฐ user ์ ๊ทผ 0)
-- ์ด์์ ์ค์ ๊ฐ (warm pool toggle ๋ฑ) โ ๋จ์ผ row ์ key/value
CREATE TABLE IF NOT EXISTS public.system_settings (
key TEXT PRIMARY KEY,
value JSONB NOT NULL,
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
-- ๊ธฐ๋ณธ๊ฐ โ warm pool ๋นํ์ฑ, max_instances=8 (cap)
INSERT INTO public.system_settings(key, value) VALUES
('tts_scale_warm_pool_enabled', 'false'::jsonb),
('tts_scale_max_instances', '8'::jsonb)
ON CONFLICT (key) DO NOTHING;
ALTER TABLE public.system_settings ENABLE ROW LEVEL SECURITY;
|