2025-01-23 14:56:20 +00:00
|
|
|
CREATE TABLE documents (
|
2025-02-07 12:12:51 +00:00
|
|
|
id uuid primary key DEFAULT uuid_generate_v7(),
|
2025-03-10 11:03:00 +00:00
|
|
|
clientId uuid not null,
|
2025-01-24 16:12:25 +00:00
|
|
|
hash text not null,
|
2025-03-10 11:03:00 +00:00
|
|
|
foreign key (clientId) references clients(id),
|
|
|
|
|
unique(clientId, hash)
|
2025-02-05 17:44:01 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
CREATE TABLE documentEntries (
|
2025-02-07 12:12:51 +00:00
|
|
|
id uuid primary key DEFAULT uuid_generate_v7(),
|
2025-02-05 17:44:01 +00:00
|
|
|
documentId uuid not null,
|
|
|
|
|
bucket text not null,
|
2025-02-07 12:12:51 +00:00
|
|
|
key text not null,
|
2025-02-05 17:44:01 +00:00
|
|
|
foreign key (documentId) references documents(id)
|
2025-02-07 12:12:51 +00:00
|
|
|
);
|
|
|
|
|
|
2025-03-03 21:56:17 +00:00
|
|
|
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
|
|
|
|
2025-02-07 12:12:51 +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,
|
2025-03-03 21:56:17 +00:00
|
|
|
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)
|
|
|
|
|
)
|
2025-02-07 12:12:51 +00:00
|
|
|
);
|
2025-02-07 14:15:06 +00:00
|
|
|
|
2025-03-03 21:56:17 +00:00
|
|
|
CREATE TABLE documentCleanEntries (
|
|
|
|
|
id uuid primary key DEFAULT uuid_generate_v7(),
|
|
|
|
|
cleanId uuid not null,
|
2025-03-11 18:15:49 +00:00
|
|
|
version bigint not null,
|
2025-03-03 21:56:17 +00:00
|
|
|
foreign key (cleanId) references documentCleans(id)
|
|
|
|
|
);
|
|
|
|
|
|
2025-02-07 14:15:06 +00:00
|
|
|
CREATE TABLE documentTextExtractions (
|
|
|
|
|
id uuid primary key DEFAULT uuid_generate_v7(),
|
2025-02-20 19:02:44 +00:00
|
|
|
cleanEntryId uuid not null,
|
2025-03-11 18:15:49 +00:00
|
|
|
version bigint not null,
|
2025-02-07 14:15:06 +00:00
|
|
|
bucket text not null,
|
|
|
|
|
key text not null,
|
2025-02-20 19:02:44 +00:00
|
|
|
foreign key (cleanEntryId) references documentCleans(id)
|
2025-02-07 14:15:06 +00:00
|
|
|
);
|