Skip to content

Commit 99b18ec

Browse files
authored
fix(supabase): also wrap ENABLE ROW LEVEL SECURITY in DO blocks (#2839)
ENABLE RLS on an existing table also requires ownership. PR #2838 fixed CREATE INDEX and CREATE POLICY but missed this one. New deploy run (#27032734172) failed at line 30 of 20260530120000.
1 parent b499f99 commit 99b18ec

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

supabase/migrations/20260530120000_add_smtp_senders.sql

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,26 @@ CREATE TABLE IF NOT EXISTS private.smtp_senders (
1818
UNIQUE(user_id, email)
1919
);
2020

21-
-- CREATE INDEX / CREATE POLICY on an existing table require ownership.
22-
-- On QA the table may have been pre-applied by a role that doesn't match
23-
-- the migration runner, so these no-op cleanly when we lack privilege.
21+
-- CREATE INDEX / CREATE POLICY / ENABLE RLS on an existing table require
22+
-- ownership. On QA the table may have been pre-applied by a role that
23+
-- doesn't match the migration runner, so these no-op cleanly when we lack
24+
-- privilege. Whoever pre-applied the table is responsible for the
25+
-- index / RLS / policy.
2426
DO $$
2527
BEGIN
2628
CREATE INDEX idx_smtp_senders_user_id ON private.smtp_senders(user_id);
2729
EXCEPTION WHEN insufficient_privilege OR duplicate_table THEN NULL;
2830
END $$;
2931

30-
ALTER TABLE private.smtp_senders ENABLE ROW LEVEL SECURITY;
32+
DO $$
33+
BEGIN
34+
EXECUTE 'ALTER TABLE private.smtp_senders ENABLE ROW LEVEL SECURITY';
35+
EXCEPTION WHEN insufficient_privilege THEN NULL;
36+
END $$;
3137

3238
DO $$
3339
BEGIN
3440
EXECUTE 'DROP POLICY IF EXISTS "Users can manage own smtp_senders" ON private.smtp_senders';
3541
EXECUTE 'CREATE POLICY "Users can manage own smtp_senders" ON private.smtp_senders USING (auth.uid() = user_id) WITH CHECK (auth.uid() = user_id)';
36-
EXCEPTION WHEN insufficient_privilege THEN NULL;
42+
EXCEPTION WHEN insufficient_privilege OR duplicate_object THEN NULL;
3743
END $$;

supabase/migrations/20260601000000_add_whatsapp_gateway.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ DO $$ BEGIN CREATE INDEX idx_whatsapp_sessions_status ON private.whatsapp_sessio
4040
DO $$ BEGIN CREATE INDEX idx_whatsapp_sessions_active ON private.whatsapp_sessions(is_active); EXCEPTION WHEN insufficient_privilege OR duplicate_table THEN NULL; END $$;
4141

4242
-- Enable RLS
43-
ALTER TABLE private.whatsapp_sessions ENABLE ROW LEVEL SECURITY;
43+
DO $$ BEGIN EXECUTE 'ALTER TABLE private.whatsapp_sessions ENABLE ROW LEVEL SECURITY'; EXCEPTION WHEN insufficient_privilege THEN NULL; END $$;
4444

4545
-- RLS Policies for whatsapp_sessions
4646
DO $$ BEGIN EXECUTE 'DROP POLICY IF EXISTS "Users can view own whatsapp sessions" ON private.whatsapp_sessions'; EXECUTE 'CREATE POLICY "Users can view own whatsapp sessions" ON private.whatsapp_sessions FOR SELECT USING (auth.uid() = user_id)'; EXCEPTION WHEN insufficient_privilege OR duplicate_object THEN NULL; END $$;

0 commit comments

Comments
 (0)