rotation config migration
This commit is contained in:
parent
8bf0dc13d7
commit
9178b438a2
44
supabase/migrations/20260308150000_rotation_config.sql
Normal file
44
supabase/migrations/20260308150000_rotation_config.sql
Normal file
|
|
@ -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
|
||||
$$;
|
||||
Loading…
Reference in New Issue
Block a user