-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupabase_playlists_schema.sql
More file actions
41 lines (34 loc) · 1.55 KB
/
Copy pathsupabase_playlists_schema.sql
File metadata and controls
41 lines (34 loc) · 1.55 KB
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
-- Run these queries in your Supabase SQL Editor to create the required tables
-- 1. Create Playlists Table
CREATE TABLE public.playlists (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
user_id UUID REFERENCES auth.users(id) NOT NULL,
name TEXT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- 2. Create Playlist Stations Table (maps stations to playlists)
CREATE TABLE public.playlist_stations (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
playlist_id UUID REFERENCES public.playlists(id) ON DELETE CASCADE NOT NULL,
user_id UUID REFERENCES auth.users(id) NOT NULL,
station_id TEXT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- 3. Create Favorites Table (maps user favorites)
CREATE TABLE public.favorites (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
user_id UUID REFERENCES auth.users(id) NOT NULL,
station_id TEXT NOT NULL,
station_name TEXT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- 4. Set up Row Level Security (RLS)
ALTER TABLE public.playlists ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.playlist_stations ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.favorites ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Users can manage their own playlists" ON public.playlists
FOR ALL USING (auth.uid() = user_id);
CREATE POLICY "Users can manage their own playlist stations" ON public.playlist_stations
FOR ALL USING (auth.uid() = user_id);
CREATE POLICY "Users can manage their own favorites" ON public.favorites
FOR ALL USING (auth.uid() = user_id);