DO $$
DECLARE
	_path character varying(256) := 'patch-2026_01_19-UserEmails';
	_build integer := 15815;
BEGIN
	IF EXISTS (SELECT 1 FROM public."Versions" WHERE "Path" = _path) THEN
		RETURN;
	END IF;

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

	BEGIN
		ALTER TABLE public."UserEmails"
			ADD "SmtpStatus" int,
			ADD "SmtpStatusTimestamp" timestamp,
			ADD "SmtpError" character varying(1024),
			ADD "ImapSendStatus" int,
			ADD "ImapSendStatusTimestamp" timestamp,
			ADD "ImapSendError" character varying(1024),
			ADD "ImapSyncStatus" int,
			ADD "ImapSyncStatusTimestamp" timestamp,
			ADD "ImapSyncError" character varying(1024),
			ADD "PopStatus" int,
			ADD "PopStatusTimestamp" timestamp,
			ADD "PopError" character varying(1024);

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

	EXCEPTION
		WHEN OTHERS THEN
			RAISE NOTICE '[ERR] %: %', _path, SQLERRM;
	END;
END;
$$;