-- Run against each project business database during the coordinated Server cutover. -- Historical tasks are explicitly assigned to production; retain existing scopes. BEGIN; SET LOCAL lock_timeout = '3s'; SET LOCAL statement_timeout = '30s'; UPDATE workbench.operational_tasks SET document = jsonb_set(document, '{execution_scope}', '"production"'::jsonb) WHERE NOT (document ? 'execution_scope'); DO $$ BEGIN IF NOT EXISTS ( SELECT 1 FROM pg_constraint WHERE conrelid = 'workbench.operational_tasks'::regclass AND conname = 'operational_tasks_execution_scope_required' ) THEN ALTER TABLE workbench.operational_tasks ADD CONSTRAINT operational_tasks_execution_scope_required CHECK ( (jsonb_typeof(document->'execution_scope') = 'string' AND length(btrim(document->>'execution_scope')) > 0) IS TRUE ); END IF; END $$; COMMIT;