-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupabase-schema.sql
More file actions
55 lines (44 loc) · 1.5 KB
/
supabase-schema.sql
File metadata and controls
55 lines (44 loc) · 1.5 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
-- Whisper Database Schema
-- Run this in your Supabase SQL editor
-- Enable UUID extension
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
-- Rooms table
CREATE TABLE rooms (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
name TEXT NOT NULL,
is_public BOOLEAN DEFAULT true,
password_hash TEXT,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Messages table
CREATE TABLE messages (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
room_id UUID NOT NULL REFERENCES rooms(id) ON DELETE CASCADE,
user_name TEXT NOT NULL,
content TEXT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Add indexes for better performance
CREATE INDEX idx_messages_room_id ON messages(room_id);
CREATE INDEX idx_messages_created_at ON messages(created_at DESC);
CREATE INDEX idx_rooms_created_at ON rooms(created_at DESC);
-- Enable Row Level Security
ALTER TABLE rooms ENABLE ROW LEVEL SECURITY;
ALTER TABLE messages ENABLE ROW LEVEL SECURITY;
-- Policies for rooms (everyone can read and create)
CREATE POLICY "Anyone can view rooms"
ON rooms FOR SELECT
USING (true);
CREATE POLICY "Anyone can create rooms"
ON rooms FOR INSERT
WITH CHECK (true);
-- Policies for messages (everyone can read and create in rooms they have access to)
CREATE POLICY "Anyone can view messages"
ON messages FOR SELECT
USING (true);
CREATE POLICY "Anyone can create messages"
ON messages FOR INSERT
WITH CHECK (true);
CREATE POLICY "Anyone can delete messages in a room"
ON messages FOR DELETE
USING (true);