-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrebuild_settings.sql
More file actions
70 lines (57 loc) · 2.02 KB
/
rebuild_settings.sql
File metadata and controls
70 lines (57 loc) · 2.02 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
-- ========================================================
-- COMPLETE REBUILD for site_settings
-- This script DROPS the existing table and recreates it
-- Run this ENTIRE script in Supabase SQL Editor
-- ========================================================
-- Step 1: Drop the existing table completely (this removes all policies too)
DROP TABLE IF EXISTS site_settings CASCADE;
-- Step 2: Create fresh table
CREATE TABLE site_settings (
id TEXT PRIMARY KEY DEFAULT 'main',
settings JSONB NOT NULL DEFAULT '{}'::jsonb,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW()
);
-- Step 3: Enable RLS
ALTER TABLE site_settings ENABLE ROW LEVEL SECURITY;
-- Step 4: Create SIMPLE permissive policies
-- Policy 1: Allow ALL users (including anonymous) to SELECT
CREATE POLICY "public_select"
ON site_settings
FOR SELECT
USING (true);
-- Policy 2: Allow authenticated users to INSERT
CREATE POLICY "auth_insert"
ON site_settings
FOR INSERT
TO authenticated
WITH CHECK (true);
-- Policy 3: Allow authenticated users to UPDATE
CREATE POLICY "auth_update"
ON site_settings
FOR UPDATE
TO authenticated
USING (true)
WITH CHECK (true);
-- Policy 4: Allow authenticated users to DELETE (optional but useful)
CREATE POLICY "auth_delete"
ON site_settings
FOR DELETE
TO authenticated
USING (true);
-- Step 5: Grant permissions explicitly
GRANT SELECT ON site_settings TO anon;
GRANT SELECT ON site_settings TO authenticated;
GRANT INSERT ON site_settings TO authenticated;
GRANT UPDATE ON site_settings TO authenticated;
GRANT DELETE ON site_settings TO authenticated;
GRANT ALL ON site_settings TO service_role;
-- Step 6: Insert the initial row
INSERT INTO site_settings (id, settings, updated_at)
VALUES ('main', '{}'::jsonb, NOW());
-- Step 7: Verify everything
SELECT 'Table created successfully!' as step1;
SELECT tablename, policyname, cmd, permissive, roles
FROM pg_policies
WHERE tablename = 'site_settings';
SELECT * FROM site_settings;