DO $$
BEGIN
INSERT INTO public."ProjectStatuses"(
	"Name", "Color", "Type","EntityType")
	SELECT 'BeExecuted', 'gray', 2,38
WHERE Not exists(SELECT * FROM public."ProjectStatuses" WHERE "Type"=2 AND "EntityType"=38 AND "PatternId" is null);
 

INSERT INTO public."ProjectStatuses"(
	"Name", "Color", "Type","EntityType")
	SELECT 'Closed', 'lime', 5,38
WHERE Not exists(SELECT * FROM public."ProjectStatuses" WHERE "Type"=5 AND "EntityType"=38 AND "PatternId" is null);

UPDATE public."ProjectStatuses" SET "Color"='gray' WHERE "Type"=2 and "EntityId" is null;
UPDATE public."ProjectStatuses" SET "Color"='gray.8' WHERE "Type"=5 and "EntityId" is  null;

END $$