fix(tasks): isolate worker execution scopes

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.
This commit is contained in:
2026-11-08 01:54:48 +08:00
parent 2a7b96f813
commit 33df25f22b
14 changed files with 156 additions and 16 deletions
@@ -0,0 +1,26 @@
-- 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;