-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsupabase-setup.sql
More file actions
40 lines (30 loc) · 1.1 KB
/
supabase-setup.sql
File metadata and controls
40 lines (30 loc) · 1.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
CREATE TABLE documents (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
title TEXT NOT NULL,
content JSONB NOT NULL DEFAULT '[]',
last_modified TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
is_starred BOOLEAN DEFAULT FALSE,
is_archived BOOLEAN DEFAULT FALSE,
tags TEXT[] DEFAULT '{}',
word_count INTEGER DEFAULT 0,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
CREATE INDEX idx_documents_last_modified ON documents(last_modified DESC);
CREATE INDEX idx_documents_is_starred ON documents(is_starred);
CREATE INDEX idx_documents_is_archived ON documents(is_archived);
CREATE INDEX idx_documents_tags ON documents USING GIN(tags);
ALTER TABLE documents ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Allow all operations on documents" ON documents
FOR ALL USING (true);
CREATE OR REPLACE FUNCTION update_updated_at_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ language 'plpgsql';
CREATE TRIGGER update_documents_updated_at
BEFORE UPDATE ON documents
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();