CREATE TABLE IF NOT EXISTS public.short_url_visits
(
    Id         SERIAL PRIMARY KEY,
    ShortUrlId INT         NOT NULL REFERENCES public.short_urls (Id),
    Client     TEXT        NOT NULL,
    -- for history
    Deleted    BOOLEAN     NOT NULL DEFAULT FALSE,
    EditorId   INT         NULL REFERENCES administration.users (Id),
    CreatedUtc timestamptz NOT NULL DEFAULT NOW(),
    UpdatedUtc timestamptz NOT NULL DEFAULT NOW()
);

CREATE TABLE IF NOT EXISTS public.short_url_visits_history
(
    LIKE public.short_url_visits
);

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

