-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupabase-setup.sql
More file actions
50 lines (42 loc) · 1.52 KB
/
supabase-setup.sql
File metadata and controls
50 lines (42 loc) · 1.52 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
-- Create components table for storing component schemas
CREATE TABLE IF NOT EXISTS components (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name VARCHAR(255) NOT NULL,
version VARCHAR(50) NOT NULL DEFAULT '1.0.0',
author VARCHAR(255),
user_id UUID,
schema JSONB NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
UNIQUE(name, version)
);
-- Create index for faster lookups
CREATE INDEX IF NOT EXISTS idx_components_name ON components(name);
CREATE INDEX IF NOT EXISTS idx_components_user_id ON components(user_id);
CREATE INDEX IF NOT EXISTS idx_components_updated_at ON components(updated_at DESC);
-- Enable Row Level Security (RLS)
ALTER TABLE components ENABLE ROW LEVEL SECURITY;
-- Create policy to allow public read access (adjust based on your needs)
CREATE POLICY "Allow public read access" ON components
FOR SELECT
USING (true);
-- Create policy to allow authenticated users to insert/update
CREATE POLICY "Allow authenticated insert" ON components
FOR INSERT
WITH CHECK (true);
CREATE POLICY "Allow authenticated update" ON components
FOR UPDATE
USING (true);
-- Create function to update updated_at timestamp
CREATE OR REPLACE FUNCTION update_updated_at_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
-- Create trigger to automatically update updated_at
CREATE TRIGGER update_components_updated_at
BEFORE UPDATE ON components
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();