-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupabase-schema.sql
More file actions
63 lines (52 loc) · 2.1 KB
/
supabase-schema.sql
File metadata and controls
63 lines (52 loc) · 2.1 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
-- Enable UUID extension
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
-- Create videos table
CREATE TABLE videos (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
title TEXT NOT NULL,
description TEXT,
url TEXT NOT NULL,
file_path TEXT NOT NULL,
user_id UUID REFERENCES auth.users(id),
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Set up Row Level Security (RLS)
ALTER TABLE videos ENABLE ROW LEVEL SECURITY;
-- Create policies
-- Allow anyone to read videos
CREATE POLICY "Allow public read access" ON videos
FOR SELECT USING (true);
-- Allow authenticated users to insert their own videos
CREATE POLICY "Allow authenticated users to insert their own videos" ON videos
FOR INSERT TO authenticated WITH CHECK (auth.uid() = user_id);
-- Allow users to update their own videos
CREATE POLICY "Allow users to update their own videos" ON videos
FOR UPDATE TO authenticated USING (auth.uid() = user_id);
-- Allow users to delete their own videos
CREATE POLICY "Allow users to delete their own videos" ON videos
FOR DELETE TO authenticated USING (auth.uid() = user_id);
-- Create storage bucket for videos
INSERT INTO storage.buckets (id, name, public) VALUES ('videos', 'videos', true);
-- Set up storage policies
-- Allow anyone to read from the videos bucket
CREATE POLICY "Allow public read access for videos" ON storage.objects
FOR SELECT USING (bucket_id = 'videos');
-- Allow authenticated users to upload to the videos bucket
CREATE POLICY "Allow authenticated users to upload videos" ON storage.objects
FOR INSERT TO authenticated WITH CHECK (
bucket_id = 'videos' AND
auth.uid() = owner
);
-- Allow users to update their own videos in the bucket
CREATE POLICY "Allow users to update their own videos" ON storage.objects
FOR UPDATE TO authenticated USING (
bucket_id = 'videos' AND
auth.uid() = owner
);
-- Allow users to delete their own videos from the bucket
CREATE POLICY "Allow users to delete their own videos" ON storage.objects
FOR DELETE TO authenticated USING (
bucket_id = 'videos' AND
auth.uid() = owner
);