Spaces:
Sleeping
Sleeping
File size: 3,304 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 71 72 73 74 75 | -- ์ฌ์ฉ์ ์ค๋ฅ ์ ๊ณ (์ด์ ๋ชจ๋ ๋ฑ์์ "์ค๋ฅ ์ ๊ณ ํ๊ธฐ" ๋ฒํผ)
--
-- ํ๋ฉด ์คํฌ๋ฆฐ์ท + ๊ตฌ์กฐํ ๋ก๊ทธ (DrivingTimingProvider.turnLogs / SttPlugin ์ด๋ฒคํธ ๋ฑ) +
-- ๋๋ฐ์ด์ค ์ปจํ
์คํธ (platform / version / route) ๋ฅผ ๋ฐ์ ๋ณด๊ด. admin /ad โ "์ค๋ฅ ์ ๊ณ "
-- ํญ์์ ๋ชฉ๋ก/์์ธ ํ์ธ ๊ฐ๋ฅ.
--
-- Storage: ์คํฌ๋ฆฐ์ท์ ๊ธฐ์กด `scheduled-audio` bucket ์ `error-reports/<user_id>/<report_id>.png`
-- ๊ฒฝ๋ก ์ฌ์ฌ์ฉ (๋ณ๋ bucket ์ ๋ง๋ค๊ณ ๋จ์ํ).
CREATE TABLE IF NOT EXISTS public.error_reports (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
-- ์ฌ์ฉ์ ์
๋ ฅ
route TEXT NOT NULL, -- '/driving', '/message' ๋ฑ (์๋ ์บก์ฒ)
description TEXT, -- ์ ํ โ ์ฌ์ฉ์๊ฐ ์
๋ ฅํ ํ ์ค ๋ฉ๋ชจ
-- ์๋ ์ฒจ๋ถ
screenshot_path TEXT, -- storage path (signed URL ์ผ๋ก admin ํ์)
screenshot_url TEXT, -- signed URL (1๋
)
logs JSONB, -- ๊ตฌ์กฐํ ๋ก๊ทธ (turnLogs, events ๋ฑ)
context JSONB, -- ๋๋ฐ์ด์ค/ํ๋ซํผ ์ ๋ณด
-- admin ์ฒ๋ฆฌ ์ํ
handled BOOLEAN NOT NULL DEFAULT FALSE,
handled_at TIMESTAMPTZ,
admin_note TEXT, -- admin ๋ฉ๋ชจ (ํด๊ฒฐ์ฑ
/ ๋ถ๋ฅ)
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_error_reports_created
ON public.error_reports (created_at DESC);
CREATE INDEX IF NOT EXISTS idx_error_reports_unhandled
ON public.error_reports (created_at DESC)
WHERE handled = FALSE;
ALTER TABLE public.error_reports ENABLE ROW LEVEL SECURITY;
-- ์ฌ์ฉ์: ๋ณธ์ธ ์ ๊ณ ๋ง INSERT
DROP POLICY IF EXISTS error_reports_insert ON public.error_reports;
CREATE POLICY error_reports_insert ON public.error_reports
FOR INSERT
WITH CHECK (user_id = auth.uid());
-- ์ฌ์ฉ์: ๋ณธ์ธ ์ ๊ณ ๋ง SELECT (์๊ธฐ ์ ๊ณ ๋ชฉ๋ก ํ์ธ์ฉ, ํฅํ ์ฌ์ฉ)
DROP POLICY IF EXISTS error_reports_select_own ON public.error_reports;
CREATE POLICY error_reports_select_own ON public.error_reports
FOR SELECT
USING (user_id = auth.uid());
-- admin (service_role ์ฌ์ฉ) ์ RLS bypass โ ๋ชจ๋ ์ ๊ณ ์กฐํ/๊ฐฑ์ ๊ฐ๋ฅ.
CREATE OR REPLACE FUNCTION public._error_reports_touch_updated_at()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
DROP TRIGGER IF EXISTS error_reports_touch_updated_at ON public.error_reports;
CREATE TRIGGER error_reports_touch_updated_at
BEFORE UPDATE ON public.error_reports
FOR EACH ROW EXECUTE FUNCTION public._error_reports_touch_updated_at();
COMMENT ON TABLE public.error_reports IS
'์ฌ์ฉ์ ์ค๋ฅ ์ ๊ณ โ ํ๋ฉด ์คํฌ๋ฆฐ์ท + ๋ก๊ทธ + ๋๋ฐ์ด์ค ์ปจํ
์คํธ.';
COMMENT ON COLUMN public.error_reports.logs IS
'๊ตฌ์กฐํ ๋ก๊ทธ. ์ด์ ๋ชจ๋: {"turn_logs": [...], "events": [...]}.';
COMMENT ON COLUMN public.error_reports.context IS
'๋๋ฐ์ด์ค ์ปจํ
์คํธ: {"platform": "ios", "version": "26.4", "app_version": "...", "user_agent": "..."}.';
|