Spaces:
Sleeping
Sleeping
Download backend/sql/001_credits.sql from stylevoice/talk: direct link, hf CLI and curl.
- Browser
- Download file 2.57 kB
-
https://huggingface.co/spaces/stylevoice/talk/resolve/main/backend/sql/001_credits.sql
- Command line
-
hf download hf://spaces/stylevoice/talk/backend/sql/001_credits.sql
-
curl -L -o 001_credits.sql https://huggingface.co/spaces/stylevoice/talk/resolve/main/backend/sql/001_credits.sql
2.57 kB
| -- ํฌ๋ ๋ง ์์คํ ํ ์ด๋ธ (Supabase SQL Editor์์ ์คํ) | |
| -- 1. ์ฌ์ฉ์ ํฌ๋ ๋ง ์์ก | |
| CREATE TABLE IF NOT EXISTS public.user_credits ( | |
| user_id UUID PRIMARY KEY REFERENCES auth.users(id) ON DELETE CASCADE, | |
| balance INTEGER NOT NULL DEFAULT 100, | |
| total_earned INTEGER NOT NULL DEFAULT 100, | |
| total_spent INTEGER NOT NULL DEFAULT 0, | |
| daily_reset_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), | |
| created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), | |
| updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() | |
| ); | |
| -- RLS: ๋ณธ์ธ๋ง ์กฐํ, service_role๋ง ์์ | |
| ALTER TABLE public.user_credits ENABLE ROW LEVEL SECURITY; | |
| CREATE POLICY "Users can read own credits" ON public.user_credits | |
| FOR SELECT USING (auth.uid() = user_id); | |
| -- 2. ํฌ๋ ๋ง ๋ณ๋ ๋ก๊ทธ | |
| CREATE TABLE IF NOT EXISTS public.credit_logs ( | |
| id BIGSERIAL PRIMARY KEY, | |
| user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE, | |
| amount INTEGER NOT NULL, -- ์์=์ถฉ์ , ์์=์ฐจ๊ฐ | |
| reason TEXT NOT NULL DEFAULT '', | |
| detail JSONB NOT NULL DEFAULT '{}', | |
| created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() | |
| ); | |
| ALTER TABLE public.credit_logs ENABLE ROW LEVEL SECURITY; | |
| CREATE POLICY "Users can read own logs" ON public.credit_logs | |
| FOR SELECT USING (auth.uid() = user_id); | |
| CREATE INDEX IF NOT EXISTS idx_credit_logs_user ON public.credit_logs(user_id, created_at DESC); | |
| -- 3. ์ฟ ํฐ ํ ์ด๋ธ | |
| CREATE TABLE IF NOT EXISTS public.coupons ( | |
| id BIGSERIAL PRIMARY KEY, | |
| code TEXT NOT NULL UNIQUE, | |
| credit_amount INTEGER NOT NULL DEFAULT 10000, | |
| max_uses INTEGER NOT NULL DEFAULT 1, | |
| used_count INTEGER NOT NULL DEFAULT 0, | |
| active BOOLEAN NOT NULL DEFAULT TRUE, | |
| expires_at TIMESTAMPTZ, | |
| created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() | |
| ); | |
| ALTER TABLE public.coupons ENABLE ROW LEVEL SECURITY; | |
| -- ์ฟ ํฐ์ service_role๋ก๋ง ๊ด๋ฆฌ | |
| -- 4. ์ฟ ํฐ ์ฌ์ฉ ์ด๋ ฅ | |
| CREATE TABLE IF NOT EXISTS public.coupon_redemptions ( | |
| id BIGSERIAL PRIMARY KEY, | |
| user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE, | |
| coupon_id BIGINT NOT NULL REFERENCES public.coupons(id), | |
| credit_amount INTEGER NOT NULL, | |
| created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), | |
| UNIQUE(user_id, coupon_id) -- 1์ธ 1ํ ์ฌ์ฉ | |
| ); | |
| ALTER TABLE public.coupon_redemptions ENABLE ROW LEVEL SECURITY; | |
| CREATE POLICY "Users can read own redemptions" ON public.coupon_redemptions | |
| FOR SELECT USING (auth.uid() = user_id); | |
| -- 5. ํ ์คํธ ์ฟ ํฐ ์ฝ์ (ํ์์) | |
| -- INSERT INTO public.coupons (code, credit_amount, max_uses) VALUES ('WELCOME2026', 10000, 100); | |