DO $$
	BEGIN
		IF EXISTS (SELECT "Id" FROM public."Versions" WHERE "Build">=14268) THEN
			RETURN;
		END IF;
		BEGIN
			INSERT INTO public."Applications"("Key", "Name")
			SELECT 'team','Команды' WHERE NOT EXISTS(SELECT "Key" FROM public."Applications" WHERE "Key"='team' );

			IF EXISTS (SELECT "Id" FROM public."AuthClients" WHERE "ApplicationKey"='commands' OR "ApplicationKey"='team') THEN
				RETURN;
			END IF;
			
			INSERT INTO public."AuthClients"("Name", "ClientId", "ClientSecret", "RedirectUrl", "ApplicationKey")
			VALUES('Команды', md5(random()::text || current_timestamp::text)::uuid::text, md5(random()::text || current_timestamp::text)::uuid::text, '', 'team');
			
		EXCEPTION
			WHEN OTHERS THEN RAISE NOTICE 'Init Comand OAuth application <AuthClients> error.';
		END;
	END;
$$
