DO $$ 
	DECLARE  _path character varying(256) := 'patch-2025_10_31_UpdateUserActionsTypeCode';

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

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

		BEGIN

		  UPDATE public."UserActions" SET "TypeCode" = 'UserLogin' WHERE "Type" = 260 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'AuthError' WHERE "Type" = 263 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'Logout' WHERE "Type" = 264 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'AddDocument' WHERE "Type" = 23 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'DeleteDocument' WHERE "Type" = 180 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'DeleteTrashDocument' WHERE "Type" = 192 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'DeleteGlobalTrashDocument' WHERE "Type" = 193 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'DeleteCalendar' WHERE "Type" = 19 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'AddFavoriteContact' WHERE "Type" = 27 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'AddFavoriteDocument' WHERE "Type" = 28 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'AddLink' WHERE "Type" = 25 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'AddExternalLink' WHERE "Type" = 26 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'DownloadDocument' WHERE "Type" = 120 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'UploadDocument' WHERE "Type" = 121 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'DownloadDocumentByLink' WHERE "Type" = 124 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'DocumentOpen' WHERE "Type" = 125 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'DocumentOpenUid' WHERE "Type" = 126 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'DocumentEdit' WHERE "Type" = 127 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'EntityShareEvent' WHERE "Type" = 130 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'EntityShareCalendar' WHERE "Type" = 131 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'EntityShareProjects' WHERE "Type" = 132 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'DeleteDirectory' WHERE "Type" = 181 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'DeleteEvent' WHERE "Type" = 184 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'GetDocuments' WHERE "Type" = 41 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'RestoreDirectory' WHERE "Type" = 191 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'MoveDocument' WHERE "Type" = 199 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'DeleteUser' WHERE "Type" = 268 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'DeleteUserWithTransfer' WHERE "Type" = 269 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'ChangeTokenDuration' WHERE "Type" = 500 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'PasswordEnterCount' WHERE "Type" = 501 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'UserIpWhiteList' WHERE "Type" = 503 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'AdminIpWhiteList' WHERE "Type" = 502 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'ChangeLdapSettings' WHERE "Type" = 504 AND "TypeCode" IS NULL;
       UPDATE public."UserActions" SET "TypeCode" = 'AddDirectory' WHERE "Type" = 24 AND "TypeCode" IS NULL;

 			INSERT INTO public."Versions" ("Path", "Build") VALUES (_path, 0);
			EXCEPTION
				WHEN OTHERS THEN RAISE NOTICE '[ERR] %: %', _path, SQLERRM;
		END;
	END;
$$
