DO $$DECLARE
   this_version CONSTANT varchar := '00.01.039';
BEGIN
   PERFORM * FROM "DBVersion" WHERE version = this_version;
   IF FOUND THEN RETURN; END IF;

    CREATE TABLE public."ntf_InAppNotification"
    (
        id uuid NOT NULL,
        "user" uuid NOT NULL,
        type uuid NOT NULL,
        read_time timestamp without time zone,
        tracking_state smallint NOT NULL,
        priority smallint NOT NULL,
        subject character varying COLLATE pg_catalog."default",
        body character varying COLLATE pg_catalog."default",
        extra_data character varying COLLATE pg_catalog."default",
        created_at timestamp without time zone NOT NULL,
        updated_at timestamp without time zone NOT NULL,
        tenant uuid,
        is_active smallint NOT NULL,
        CONSTRAINT "ntf_InAppNotification_pkey" PRIMARY KEY (id),
        CONSTRAINT "ntf_InAppNotification_tenant_fkey" FOREIGN KEY (tenant)
            REFERENCES public."Tenant" (id) MATCH SIMPLE
            ON UPDATE NO ACTION
            ON DELETE NO ACTION,
        CONSTRAINT "ntf_InAppNotification_user_fkey" FOREIGN KEY ("user")
            REFERENCES public."User" (id) MATCH SIMPLE
            ON UPDATE NO ACTION
            ON DELETE NO ACTION
    );

    INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.039', '2023-12-05 12:00:00.000000+02', now(), 'Add table ntf_InAppNotification.');

END$$;