File size: 2,925 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
-- 카페 BGM μƒ˜ν”Œ νŽΈμ„±ν‘œ DBν™” (2026-05-25).
--
-- κΈ°μ‘΄: μƒ˜ν”Œ(μŠ€νƒ€λ²…μŠ€/올리브영)이 ν”„λ‘ νŠΈ ν•˜λ“œμ½”λ”© β†’ κ΄€λ¦¬μžκ°€ νŽΈμ§‘/μ €μž₯해도 μ˜μ† μ•ˆ 됨.
-- λ³€κ²½: μƒ˜ν”Œμ„ μ‹€μ œ music_timelines ν–‰(is_sample=true)으둜 λ§Œλ“€μ–΄ κ΄€λ¦¬μž νŽΈμ§‘μ΄ μ˜μ† +
--       λͺ¨λ“  μ‚¬μš©μžκ°€ 같은 μƒ˜ν”Œμ„ λ΄„. owner = κ΄€λ¦¬μž(icesgg). μ½κΈ°λŠ” λˆ„κ΅¬λ‚˜, μ“°κΈ°λŠ” κ΄€λ¦¬μžλ§Œ
--       (λ°±μ—”λ“œ timeline_service κ°€λ“œ + μ•„λž˜ RLS public read).
--
-- νšŒκ·€ 0: 컬럼 μΆ”κ°€(nullable/default) + μ‹ κ·œ RLSλŠ” SELECT 만 μΆ”κ°€(κΈ°μ‘΄ owner FOR ALL μœ μ§€).

ALTER TABLE public.music_timelines
    ADD COLUMN IF NOT EXISTS is_sample   boolean NOT NULL DEFAULT false,
    ADD COLUMN IF NOT EXISTS description text,
    ADD COLUMN IF NOT EXISTS genre       text,
    ADD COLUMN IF NOT EXISTS time_label  text;

CREATE INDEX IF NOT EXISTS music_timelines_sample_idx
    ON public.music_timelines (is_sample) WHERE is_sample;

-- 곡용 μƒ˜ν”Œμ€ λˆ„κ΅¬λ‚˜ 읽기 (owner μ „μš© 정책에 SELECT ν•œ 쀄 μΆ”κ°€ β€” permissive OR).
-- λ°±μ—”λ“œλŠ” service_role 둜 μš°νšŒν•˜μ§€λ§Œ RLS 도 λ°©μ–΄μ„ μœΌλ‘œ λ§žμΆ°λ‘”λ‹€.
DROP POLICY IF EXISTS music_timelines_sample_read ON public.music_timelines;
CREATE POLICY music_timelines_sample_read ON public.music_timelines
    FOR SELECT USING (is_sample = true);

DROP POLICY IF EXISTS timeline_items_sample_read ON public.timeline_items;
CREATE POLICY timeline_items_sample_read ON public.timeline_items
    FOR SELECT USING (
        EXISTS (SELECT 1 FROM public.music_timelines t
                WHERE t.id = timeline_items.timeline_id AND t.is_sample = true)
    );

-- μƒ˜ν”Œ 2개 μ‹œλ“œ (owner = κ΄€λ¦¬μž). λ©±λ“± β€” 같은 name 의 μƒ˜ν”Œμ΄ 이미 있으면 skip.
INSERT INTO public.music_timelines (user_id, name, is_sample, description, genre, time_label)
SELECT u.id, 'μŠ€νƒ€λ²…μŠ€ λ§€μž₯ ν”Œλ ˆμ΄ 리슀트', true,
       'μ„Έλ ¨λœ μž¬μ¦ˆμ™€ λΆ€λ“œλŸ¬μš΄ μ•„μΏ μŠ€ν‹± μŒμ•…μ΄ μ‘°ν•©λœ μŠ€νƒ€λ²…μŠ€ μŠ€νƒ€μΌ νŽΈμ„±ν‘œμž…λ‹ˆλ‹€.',
       'JAZZ', '08:00 - 11:00'
FROM auth.users u
WHERE u.email = 'icesgg@gmail.com'
  AND NOT EXISTS (
      SELECT 1 FROM public.music_timelines
      WHERE is_sample = true AND name = 'μŠ€νƒ€λ²…μŠ€ λ§€μž₯ ν”Œλ ˆμ΄ 리슀트');

INSERT INTO public.music_timelines (user_id, name, is_sample, description, genre, time_label)
SELECT u.id, '올리브영 μ΅œμ‹  νŠΈλ Œλ”” 팝', true,
       'ν™œκΈ°μ°¬ λ§€μž₯ λΆ„μœ„κΈ°λ₯Ό μœ„ν•œ μ΅œμ‹  인기 팝과 λΈŒλžœλ“œ 곡지사항이 ν¬ν•¨λœ κ΅¬μ„±μž…λ‹ˆλ‹€.',
       'TRENDY', '11:30 - 14:00'
FROM auth.users u
WHERE u.email = 'icesgg@gmail.com'
  AND NOT EXISTS (
      SELECT 1 FROM public.music_timelines
      WHERE is_sample = true AND name = '올리브영 μ΅œμ‹  νŠΈλ Œλ”” 팝');

COMMENT ON COLUMN public.music_timelines.is_sample IS
    '곡용 μƒ˜ν”Œ νŽΈμ„±ν‘œ(ν…œν”Œλ¦Ώ). true=λͺ¨λ“  μ‚¬μš©μž λ…ΈμΆœ, κ΄€λ¦¬μžλ§Œ νŽΈμ§‘. λ‚΄ νŽΈμ„±ν‘œ λͺ©λ‘ μ œμ™Έ.';