CREATE TABLE IF NOT EXISTS system.files
(
    Id         SERIAL PRIMARY KEY,
    FileId     TEXT        NOT NULL,
    Path       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 system.files_history
(
    LIKE system.files
);

CREATE TRIGGER files_history_trigger
    BEFORE INSERT OR UPDATE OR DELETE
    ON system.files
    FOR EACH ROW
EXECUTE FUNCTION public.history_trigger_function();