Skip to content

Commit 0b25014

Browse files
authored
fix: commit the reconcile migration policy guards (#7)
The previous commit message claimed this but housekeeping reverted the file before it was committed - caught by an independent trail audit. Staging is unaffected (it applied the guarded file from disk during the release push); this makes fresh database chains from the repo apply cleanly too.
1 parent 1fac1ee commit 0b25014

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎supabase/migrations/20260820070000_reconcile_prod_only_objects.sql‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,15 @@ CREATE INDEX IF NOT EXISTS "idx_curated_sources_active" ON "public"."curated_sou
3535
CREATE INDEX IF NOT EXISTS "idx_curated_sources_source_type" ON "public"."curated_sources" USING btree (source_type) WHERE (is_active = true);
3636
CREATE INDEX IF NOT EXISTS "idx_curated_sources_topic_tags" ON "public"."curated_sources" USING gin (topic_tags);
3737
ALTER TABLE "public"."curated_sources" ENABLE ROW LEVEL SECURITY;
38+
DROP POLICY IF EXISTS "Authenticated users can read active curated sources" ON "public"."curated_sources";
3839
CREATE POLICY "Authenticated users can read active curated sources" ON "public"."curated_sources" FOR SELECT TO authenticated USING (is_active = true);
40+
DROP POLICY IF EXISTS "Admins can insert curated sources" ON "public"."curated_sources";
3941
CREATE POLICY "Admins can insert curated sources" ON "public"."curated_sources" FOR INSERT TO authenticated
4042
WITH CHECK (EXISTS (SELECT 1 FROM public.user_roles WHERE user_roles.user_id = (SELECT auth.uid()) AND user_roles.role = 'admin'::text));
43+
DROP POLICY IF EXISTS "Admins can update curated sources" ON "public"."curated_sources";
4144
CREATE POLICY "Admins can update curated sources" ON "public"."curated_sources" FOR UPDATE TO authenticated
4245
USING (EXISTS (SELECT 1 FROM public.user_roles WHERE user_roles.user_id = (SELECT auth.uid()) AND user_roles.role = 'admin'::text));
46+
DROP POLICY IF EXISTS "Admins can delete curated sources" ON "public"."curated_sources";
4347
CREATE POLICY "Admins can delete curated sources" ON "public"."curated_sources" FOR DELETE TO authenticated
4448
USING (EXISTS (SELECT 1 FROM public.user_roles WHERE user_roles.user_id = (SELECT auth.uid()) AND user_roles.role = 'admin'::text));
4549
GRANT ALL ON TABLE "public"."curated_sources" TO anon, authenticated, service_role;
@@ -105,6 +109,7 @@ CREATE INDEX IF NOT EXISTS "idx_evidence_cards_tags" ON "public"."evidence_cards
105109
CREATE INDEX IF NOT EXISTS "idx_evidence_cards_user_id" ON "public"."evidence_cards" USING btree (user_id);
106110
CREATE OR REPLACE TRIGGER "evidence_cards_set_updated_at" BEFORE UPDATE ON "public"."evidence_cards" FOR EACH ROW EXECUTE FUNCTION "public"."set_updated_at"();
107111
ALTER TABLE "public"."evidence_cards" ENABLE ROW LEVEL SECURITY;
112+
DROP POLICY IF EXISTS "evidence_cards_own" ON "public"."evidence_cards";
108113
CREATE POLICY "evidence_cards_own" ON "public"."evidence_cards" TO authenticated
109114
USING (user_id = (SELECT auth.uid())) WITH CHECK (user_id = (SELECT auth.uid()));
110115
GRANT ALL ON TABLE "public"."evidence_cards" TO anon, authenticated, service_role;
@@ -127,6 +132,7 @@ CREATE TABLE IF NOT EXISTS "public"."sparring_sessions" (
127132
CONSTRAINT "sparring_sessions_user_side_check" CHECK (user_side = ANY (ARRAY['pro'::text, 'con'::text]))
128133
);
129134
ALTER TABLE "public"."sparring_sessions" ENABLE ROW LEVEL SECURITY;
135+
DROP POLICY IF EXISTS "Users own sessions" ON "public"."sparring_sessions";
130136
CREATE POLICY "Users own sessions" ON "public"."sparring_sessions" USING ((SELECT auth.uid()) = user_id);
131137
GRANT ALL ON TABLE "public"."sparring_sessions" TO anon, authenticated, service_role;
132138

@@ -141,7 +147,9 @@ CREATE TABLE IF NOT EXISTS "public"."keepalive_events" (
141147
);
142148
ALTER SEQUENCE "public"."keepalive_events_id_seq" OWNED BY "public"."keepalive_events"."id";
143149
ALTER TABLE "public"."keepalive_events" ENABLE ROW LEVEL SECURITY;
150+
DROP POLICY IF EXISTS "keepalive_events_anon_insert" ON "public"."keepalive_events";
144151
CREATE POLICY "keepalive_events_anon_insert" ON "public"."keepalive_events" FOR INSERT TO anon WITH CHECK (source = 'external-keepalive-monitor'::text);
152+
DROP POLICY IF EXISTS "keepalive_events_anon_select" ON "public"."keepalive_events";
145153
CREATE POLICY "keepalive_events_anon_select" ON "public"."keepalive_events" FOR SELECT TO anon USING (source = 'external-keepalive-monitor'::text);
146154
GRANT ALL ON TABLE "public"."keepalive_events" TO anon, authenticated, service_role;
147155

@@ -152,8 +160,11 @@ CREATE TABLE IF NOT EXISTS "public"."keepalive_heartbeat" (
152160
"details" jsonb DEFAULT '{}'::jsonb NOT NULL
153161
);
154162
ALTER TABLE "public"."keepalive_heartbeat" ENABLE ROW LEVEL SECURITY;
163+
DROP POLICY IF EXISTS "keepalive_heartbeat_anon_insert" ON "public"."keepalive_heartbeat";
155164
CREATE POLICY "keepalive_heartbeat_anon_insert" ON "public"."keepalive_heartbeat" FOR INSERT TO anon WITH CHECK (id = ANY (ARRAY['external-keepalive'::text, 'rpc-keepalive'::text]));
165+
DROP POLICY IF EXISTS "keepalive_heartbeat_anon_select" ON "public"."keepalive_heartbeat";
156166
CREATE POLICY "keepalive_heartbeat_anon_select" ON "public"."keepalive_heartbeat" FOR SELECT TO anon USING (id = ANY (ARRAY['external-keepalive'::text, 'rpc-keepalive'::text]));
167+
DROP POLICY IF EXISTS "keepalive_heartbeat_anon_update" ON "public"."keepalive_heartbeat";
157168
CREATE POLICY "keepalive_heartbeat_anon_update" ON "public"."keepalive_heartbeat" FOR UPDATE TO anon
158169
USING (id = ANY (ARRAY['external-keepalive'::text, 'rpc-keepalive'::text])) WITH CHECK (id = ANY (ARRAY['external-keepalive'::text, 'rpc-keepalive'::text]));
159170
GRANT ALL ON TABLE "public"."keepalive_heartbeat" TO anon, authenticated, service_role;

0 commit comments

Comments
 (0)