-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupabase-migration.sql
More file actions
37 lines (32 loc) · 1.79 KB
/
supabase-migration.sql
File metadata and controls
37 lines (32 loc) · 1.79 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
-- Create the content table for storing website content
CREATE TABLE IF NOT EXISTS content (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
section TEXT NOT NULL UNIQUE,
content JSONB NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Create an index on the section column for faster lookups
CREATE INDEX IF NOT EXISTS idx_content_section ON content(section);
-- Create a function to automatically update the 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 a trigger to automatically update the updated_at column
CREATE TRIGGER update_content_updated_at
BEFORE UPDATE ON content
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();
-- Insert initial content for the main sections
INSERT INTO content (section, content) VALUES
('home', '{"hero": {"title": "Computer & Device Repair in Central Texas—Fast. Honest. Local.", "subhead": "Expert repairs, upgrades, and IT support. Same-day diagnostics available.", "badge": "Experienced professionals. Trusted by thousands."}, "servicesSnapshot": {"title": "Expert Repairs & IT Services", "blurb": "We fix computers, phones, and networks—plus data recovery and small-business IT."}}'::jsonb)
ON CONFLICT (section) DO NOTHING;
-- Grant necessary permissions (adjust based on your Supabase setup)
-- ALTER TABLE content ENABLE ROW LEVEL SECURITY;
-- CREATE POLICY "Allow public read access" ON content FOR SELECT USING (true);
-- CREATE POLICY "Allow authenticated users to insert" ON content FOR INSERT WITH CHECK (auth.role() = 'authenticated');
-- CREATE POLICY "Allow authenticated users to update" ON content FOR UPDATE USING (auth.role() = 'authenticated');