update "TaskTypeComplexOrderTemplate"
set "TemplateExecutorGroupId" = null
where "TemplateExecutorGroupId" is not null and "TemplateExecutorGroupId" not in (select "Id" from "ExecutorGroup");

ALTER TABLE IF EXISTS public."TaskTypeComplexOrderTemplate"
    ADD CONSTRAINT "FK_TaskTypeComplexOrderTemplate_ExecutorGroupId" FOREIGN KEY ("TemplateExecutorGroupId")
    REFERENCES public."ExecutorGroup" ("Id") MATCH SIMPLE
    ON UPDATE NO ACTION
    ON DELETE SET NULL;
CREATE INDEX IF NOT EXISTS "fki_FK_TaskTypeComplexOrderTemplate_ExecutorGroupId"
    ON public."TaskTypeComplexOrderTemplate"("TemplateExecutorGroupId");