Repository navigation
Expand file tree
/
Copy pathemergency_rollback.sql
More file actions
62 lines (50 loc) · 2.39 KB
/
Copy pathemergency_rollback.sql
File metadata and controls
62 lines (50 loc) · 2.39 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
-- EMERGENCY ROLLBACK SCRIPT
-- Only use this if something breaks after running the migration
-- This restores basic functionality
-- ============================================
-- Drop all new policies
-- ============================================
DROP POLICY IF EXISTS "Users can manage their own bulletins" ON bulletins;
DROP POLICY IF EXISTS "Users can create bulletins" ON bulletins;
DROP POLICY IF EXISTS "Users can update accessible bulletins" ON bulletins;
DROP POLICY IF EXISTS "Users can delete accessible bulletins" ON bulletins;
DROP POLICY IF EXISTS "Users can read their own tokens" ON tokens;
DROP POLICY IF EXISTS "Users can create their own tokens" ON tokens;
DROP POLICY IF EXISTS "Users can update their own tokens" ON tokens;
DROP POLICY IF EXISTS "Users can delete their own tokens" ON tokens;
-- ============================================
-- Restore basic working policies
-- ============================================
-- Bulletins: Basic policies for authenticated users
CREATE POLICY "Users can manage their own bulletins"
ON bulletins FOR ALL
USING (auth.uid() = created_by)
WITH CHECK (auth.uid() = created_by);
-- Keep public reading (CRITICAL - don't remove this!)
-- NOTE: "Public bulletins are readable by anyone" should still exist
-- Tokens: Basic policies for authenticated users
CREATE POLICY "Users can read their own tokens"
ON tokens FOR SELECT
USING (auth.uid() = created_by);
CREATE POLICY "Users can create their own tokens"
ON tokens FOR INSERT
WITH CHECK (auth.uid() = created_by);
CREATE POLICY "Users can update their own tokens"
ON tokens FOR UPDATE
USING (auth.uid() = created_by)
WITH CHECK (auth.uid() = created_by);
CREATE POLICY "Users can delete their own tokens"
ON tokens FOR DELETE
USING (auth.uid() = created_by);
-- Keep anon token reading (CRITICAL - don't remove this!)
-- NOTE: "Allow anon read for public bulletin tokens" should still exist
-- ============================================
-- Drop helper functions (optional - won't hurt if left)
-- ============================================
DROP FUNCTION IF EXISTS user_has_profile_access(text, uuid);
DROP FUNCTION IF EXISTS user_can_edit_profile(text, uuid);
-- ============================================
-- DONE!
-- ============================================
-- Your site should now work as before the migration
-- You've lost collaborative editing, but core functionality is restored