-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupabase-migration-vercel.sql
More file actions
50 lines (42 loc) · 1.92 KB
/
Copy pathsupabase-migration-vercel.sql
File metadata and controls
50 lines (42 loc) · 1.92 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
-- Create the content table for storing website content
CREATE TABLE IF NOT EXISTS public.content (
id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
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 public.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 public.content
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();
-- Insert initial content for the main sections
INSERT INTO public.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;
-- Enable Row Level Security
ALTER TABLE public.content ENABLE ROW LEVEL SECURITY;
-- Create RLS policies for public read access and authenticated modifications
CREATE POLICY "public can read content"
ON public.content
FOR SELECT TO anon
USING (true);
CREATE POLICY "authenticated users can modify content"
ON public.content
FOR ALL TO authenticated
USING (true);
-- Grant necessary permissions
GRANT ALL ON public.content TO anon;
GRANT ALL ON public.content TO authenticated;
GRANT ALL ON public.content TO service_role;