Add company documents schema, uploads helper, and env wiring

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-15 10:52:06 +07:00
parent eceda5f007
commit f69313bf33
4 changed files with 145 additions and 1 deletions
+67 -1
View File
@@ -673,6 +673,68 @@ export const featureRequestVotes = pgTable(
(table) => [uniqueIndex('feature_request_votes_request_user_idx').on(table.requestId, table.userId)]
);
// ── Company Documents ──────────────────────────────────
export const companyDocumentCategoryEnum = pgEnum('company_document_category', [
'dbd_registration',
'affidavit',
'memorandum',
'articles_of_association',
'vat_registration',
'tax_id_document',
'bank_document',
'director_id',
'director_signature_card',
'shareholder_list',
'annual_filing',
'contract',
'license',
'insurance',
'other'
]);
export const companyDocuments = pgTable(
'company_documents',
{
id: uuid('id').primaryKey().defaultRandom(),
companyId: uuid('company_id')
.notNull()
.references(() => companies.id, { onDelete: 'cascade' }),
category: companyDocumentCategoryEnum('category').notNull(),
customLabel: text('custom_label'),
title: text('title').notNull(),
description: text('description'),
expiresAt: date('expires_at'),
notes: text('notes'),
createdBy: text('created_by').references(() => users.id, { onDelete: 'set null' }),
deletedAt: timestamp('deleted_at', { withTimezone: true }),
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow()
},
(table) => [index('company_documents_company_category_idx').on(table.companyId, table.category)]
);
export const companyDocumentVersions = pgTable(
'company_document_versions',
{
id: uuid('id').primaryKey().defaultRandom(),
documentId: uuid('document_id')
.notNull()
.references(() => companyDocuments.id, { onDelete: 'cascade' }),
versionNumber: integer('version_number').notNull(),
fileName: text('file_name').notNull(),
storedPath: text('stored_path').notNull(),
mimeType: text('mime_type').notNull(),
sizeBytes: integer('size_bytes').notNull(),
uploadedBy: text('uploaded_by').references(() => users.id, { onDelete: 'set null' }),
uploadedAt: timestamp('uploaded_at', { withTimezone: true }).notNull().defaultNow(),
comment: text('comment')
},
(table) => [
uniqueIndex('company_document_versions_doc_version_idx').on(table.documentId, table.versionNumber)
]
);
// ── Company Profile (bank accounts, cards, addresses) ──
export const companyAddressTypeEnum = pgEnum('company_address_type', [
@@ -819,7 +881,11 @@ export const companyLogEventEnum = pgEnum('company_log_event', [
'card_removed',
'address_added',
'address_updated',
'address_removed'
'address_removed',
'document_uploaded',
'document_version_added',
'document_metadata_updated',
'document_deleted'
]);
export const companyLog = pgTable(