DO $$ 
	DECLARE _path character varying(256) = 'patch-2026_06_01-UpdateContacts';

	BEGIN
		IF EXISTS (SELECT "Id" FROM public."Versions" WHERE "Path"=_path) THEN
			RETURN;
		END IF;

		IF EXISTS (SELECT "Id" FROM public."Versions" WHERE "Build">=16799) THEN
			RETURN;
		END IF;

		BEGIN
			UPDATE public."Contacts" SET "State"=1 where "State"<>1 AND "Id" IN (SELECT "ContactId" FROM public."Users" WHERE "Status"=1);

 
		INSERT INTO public."Versions" ("Path", "Build") VALUES (_path, 0);

			EXCEPTION
				WHEN OTHERS THEN RAISE NOTICE '[ERR] patch-2026_06_01-UpdateContacts: %', SQLERRM;
		END;
	END;
$$
