CREATE TABLE t_label_field
(
    id         INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    name       VARCHAR                        NOT NULL,
    "ORDER"    INT                            NOT NULL DEFAULT 0,
    "VALUE"    VARCHAR,
    created_at TIMESTAMP WITH TIME ZONE       NOT NULL DEFAULT now(),
    updated_at TIMESTAMP WITH TIME ZONE       NOT NULL DEFAULT now(),
    t_document INT REFERENCES t_document (id) NOT NULL
);

CREATE TABLE t_date_field
(
    id         INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    name       VARCHAR                        NOT NULL,
    "ORDER"    INT                            NOT NULL DEFAULT 0,
    "VALUE"    TIMESTAMP WITH TIME ZONE,
    created_at TIMESTAMP WITH TIME ZONE       NOT NULL DEFAULT now(),
    updated_at TIMESTAMP WITH TIME ZONE       NOT NULL DEFAULT now(),
    t_document INT REFERENCES t_document (id) NOT NULL
);

CREATE TABLE t_tag
(
    id         INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    name       VARCHAR                  NOT NULL,
    created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()
);

CREATE TABLE t_document_tagging
(
    id          INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    tag_id      INT references t_tag,
    document_id INT references t_document
);
