Persist a required Server-owned execution scope and enforce it for listing, claiming, lease recovery and SCADA verification. Backfill existing tasks explicitly through migration 034 so local development workers no longer claim production tasks from the shared database.
27 lines
932 B
PL/PgSQL
27 lines
932 B
PL/PgSQL
-- 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;
|