DO $$
	DECLARE
		_path character varying(256) := 'patch-2026_01_30-EmailMessageSnoozes';
		_build integer := 16045;
	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
			CREATE TABLE IF NOT EXISTS public."EmailMessageSnoozes"
			(
				"MessageId" bigint NOT NULL,
				"OriginalFolderId" bigint NOT NULL,
				"SnoozeUntilUtc" timestamp without time zone NOT NULL,
				"Timestamp" timestamp without time zone NOT NULL DEFAULT timezone('utc'::text, now()),
				CONSTRAINT "EmailMessageSnoozes_pkey" PRIMARY KEY ("MessageId")
			);

			CREATE INDEX IF NOT EXISTS "IDX_EmailMessageSnoozes-SnoozeUntilUtc-MessageId"
				ON public."EmailMessageSnoozes" USING btree
				("SnoozeUntilUtc" ASC, "MessageId" ASC)
				TABLESPACE pg_default;

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

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