Files
query-orchestration/database/migrations/00000000000005_documents.up.sql
T

60 lines
1.6 KiB
SQL
Raw Normal View History

2025-01-23 14:56:20 +00:00
CREATE TABLE documents (
id uuid primary key DEFAULT uuid_generate_v7(),
clientId uuid not null,
hash text not null,
foreign key (clientId) references clients(id),
unique(clientId, 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 TYPE cleanFailType AS ENUM (
'invalid_mimetype',
'invalid_read',
'invalid_read_pages',
'zero_page_count',
'large_page_count',
'large_file',
'small_dimensions',
'large_dimensions',
'small_dpi',
'large_dpi'
);
CREATE TYPE cleanMimeType AS ENUM ('application/pdf');
2025-02-28 13:11:53 +00:00
CREATE TABLE documentCleans (
id uuid primary key DEFAULT uuid_generate_v7(),
documentId uuid not null,
2025-02-28 13:11:53 +00:00
bucket text,
key text,
mimetype cleanMimeType,
2025-02-28 13:11:53 +00:00
fail cleanFailType,
foreign key (documentId) references documents(id),
CONSTRAINT bucket_and_key_together CHECK ((bucket IS NULL) = (key IS NULL) and (bucket is null) = (mimetype is null)),
CONSTRAINT location_xor_fail CHECK (
(bucket IS NOT NULL) != (fail IS NOT NULL)
)
);
CREATE TABLE documentCleanEntries (
id uuid primary key DEFAULT uuid_generate_v7(),
cleanId uuid not null,
version bigint not null,
foreign key (cleanId) references documentCleans(id)
);
CREATE TABLE documentTextExtractions (
id uuid primary key DEFAULT uuid_generate_v7(),
cleanEntryId uuid not null,
version bigint not null,
bucket text not null,
key text not null,
foreign key (cleanEntryId) references documentCleans(id)
);