From 9178b438a24800b3bbd2bd7f6c02bdaa23803b4d Mon Sep 17 00:00:00 2001 From: Marc Rejohn Castillano Date: Sun, 8 Mar 2026 17:32:13 +0800 Subject: [PATCH] rotation config migration --- .../20260308150000_rotation_config.sql | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 supabase/migrations/20260308150000_rotation_config.sql diff --git a/supabase/migrations/20260308150000_rotation_config.sql b/supabase/migrations/20260308150000_rotation_config.sql new file mode 100644 index 00000000..a0ebde3a --- /dev/null +++ b/supabase/migrations/20260308150000_rotation_config.sql @@ -0,0 +1,44 @@ +-- Seed rotation config setting for duty schedule generator +INSERT INTO app_settings (key, value) +VALUES ( + 'rotation_config', + '{ + "rotation_order": [], + "friday_am_order": [], + "excluded_staff_ids": [], + "initial_am_staff_id": null, + "initial_pm_staff_id": null + }'::jsonb +) +ON CONFLICT (key) DO NOTHING; + +-- Ensure admin/dispatcher can upsert app_settings (for rotation config edits). +-- A policy may already exist; use IF NOT EXISTS pattern via DO block. +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM pg_policies + WHERE tablename = 'app_settings' + AND policyname = 'app_settings_admin_upsert' + ) THEN + EXECUTE $policy$ + CREATE POLICY app_settings_admin_upsert ON app_settings + FOR ALL TO authenticated + USING ( + EXISTS ( + SELECT 1 FROM profiles + WHERE profiles.id = auth.uid() + AND profiles.role IN ('admin', 'dispatcher') + ) + ) + WITH CHECK ( + EXISTS ( + SELECT 1 FROM profiles + WHERE profiles.id = auth.uid() + AND profiles.role IN ('admin', 'dispatcher') + ) + ) + $policy$; + END IF; +END +$$;