CREATE TABLE public.user_invitations
(
    id          SERIAL PRIMARY KEY,
    email       VARCHAR(255) NOT NULL,
    invitation  UUID         NOT NULL,
    userSpaceId INT          NOT NULL REFERENCES public.user_spaces (Id),
    -- for history
    Deleted     BOOLEAN      NOT NULL DEFAULT FALSE,
    EditorId    INT          NULL REFERENCES administration.users (Id),
    Created     timestamptz  NOT NULL DEFAULT NOW(),
    Updated     timestamptz  NOT NULL DEFAULT NOW()
);

CREATE TABLE public.user_invitations_history
(
    LIKE public.user_invitations
);

CREATE TRIGGER user_invitations_history_trigger
    BEFORE INSERT OR UPDATE OR DELETE
    ON public.user_invitations
    FOR EACH ROW
EXECUTE FUNCTION public.history_trigger_function();