CREATE TABLE documents (
    id uuid primary key DEFAULT uuid_generate_v7(),
    jobId uuid not null,
    hash text not null,
    foreign key (jobId) references jobs(id),
    unique(jobId, hash)
);

CREATE TABLE documentEntries (
    id uuid primary key DEFAULT uuid_generate_v7(),
    documentId uuid not null,
    bucket text not null,
    key text not null,
    foreign key (documentId) references documents(id)
);

CREATE TABLE documentCleans (
    id uuid primary key DEFAULT uuid_generate_v7(),
    documentId uuid not null,
    version int not null,
    bucket text not null,
    key text not null,
    foreign key (documentId) references documents(id)
);

CREATE TABLE documentTextExtractions (
    id uuid primary key DEFAULT uuid_generate_v7(),
    cleanEntryId uuid not null,
    version int not null,
    bucket text not null,
    key text not null,
    foreign key (cleanEntryId) references documentCleans(id)
);
