--liquibase formatted sql

--changeset editor:001-create-document
CREATE TABLE document (
    id          UUID PRIMARY KEY,
    title       VARCHAR(255)             NOT NULL,
    content     TEXT                     NOT NULL,
    version     BIGINT                   NOT NULL,
    created_at  TIMESTAMP WITH TIME ZONE NOT NULL,
    updated_at  TIMESTAMP WITH TIME ZONE NOT NULL
);
--rollback DROP TABLE document;

--changeset editor:002-create-document-history
CREATE TABLE document_history (
    id           BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    document_id  UUID                     NOT NULL,
    version      BIGINT                   NOT NULL,
    title        VARCHAR(255)             NOT NULL,
    content      TEXT                     NOT NULL,
    change_type  VARCHAR(16)              NOT NULL,
    change_time  TIMESTAMP WITH TIME ZONE NOT NULL
);
--rollback DROP TABLE document_history;

--changeset editor:003-index-document-history
CREATE INDEX idx_document_history_document_id ON document_history (document_id);
--rollback DROP INDEX idx_document_history_document_id;
