feat(documents): add yachtId/companyId to files and documents

This commit is contained in:
Matt Ciaccio
2026-04-23 18:00:12 +02:00
parent 117cfae52e
commit 14dac2f3e1
4 changed files with 8656 additions and 10 deletions

View File

@@ -0,0 +1,8 @@
ALTER TABLE "documents" ADD COLUMN "yacht_id" text;--> statement-breakpoint
ALTER TABLE "documents" ADD COLUMN "company_id" text;--> statement-breakpoint
ALTER TABLE "files" ADD COLUMN "yacht_id" text;--> statement-breakpoint
ALTER TABLE "files" ADD COLUMN "company_id" text;--> statement-breakpoint
CREATE INDEX "idx_documents_yacht" ON "documents" USING btree ("yacht_id");--> statement-breakpoint
CREATE INDEX "idx_documents_company" ON "documents" USING btree ("company_id");--> statement-breakpoint
CREATE INDEX "idx_files_yacht" ON "files" USING btree ("yacht_id");--> statement-breakpoint
CREATE INDEX "idx_files_company" ON "files" USING btree ("company_id");

File diff suppressed because it is too large Load Diff

View File

@@ -50,6 +50,13 @@
"when": 1776959911400,
"tag": "0006_great_pixie",
"breakpoints": true
},
{
"idx": 7,
"version": "7",
"when": 1776959993173,
"tag": "0007_brainy_felicia_hardy",
"breakpoints": true
}
]
}

View File

@@ -15,11 +15,15 @@ import { clients } from './clients';
export const files = pgTable(
'files',
{
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
id: text('id')
.primaryKey()
.$defaultFn(() => crypto.randomUUID()),
portId: text('port_id')
.notNull()
.references(() => ports.id),
clientId: text('client_id').references(() => clients.id),
yachtId: text('yacht_id'), // FK wired in relations.ts
companyId: text('company_id'), // FK wired in relations.ts
filename: text('filename').notNull(),
originalName: text('original_name').notNull(),
mimeType: text('mime_type'),
@@ -33,18 +37,24 @@ export const files = pgTable(
(table) => [
index('idx_files_port').on(table.portId),
index('idx_files_client').on(table.clientId),
index('idx_files_yacht').on(table.yachtId),
index('idx_files_company').on(table.companyId),
],
);
export const documents = pgTable(
'documents',
{
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
id: text('id')
.primaryKey()
.$defaultFn(() => crypto.randomUUID()),
portId: text('port_id')
.notNull()
.references(() => ports.id),
interestId: text('interest_id'), // references interests.id
clientId: text('client_id').references(() => clients.id),
yachtId: text('yacht_id'), // FK wired in relations.ts
companyId: text('company_id'), // FK wired in relations.ts
documentType: text('document_type').notNull(), // eoi, contract, nda, reservation_agreement, other
title: text('title').notNull(),
status: text('status').notNull().default('draft'), // draft, sent, partially_signed, completed, expired, cancelled
@@ -61,6 +71,8 @@ export const documents = pgTable(
index('idx_docs_port').on(table.portId),
index('idx_docs_interest').on(table.interestId),
index('idx_docs_client').on(table.clientId),
index('idx_documents_yacht').on(table.yachtId),
index('idx_documents_company').on(table.companyId),
index('idx_docs_type').on(table.portId, table.documentType),
],
);
@@ -68,7 +80,9 @@ export const documents = pgTable(
export const documentSigners = pgTable(
'document_signers',
{
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
id: text('id')
.primaryKey()
.$defaultFn(() => crypto.randomUUID()),
documentId: text('document_id')
.notNull()
.references(() => documents.id, { onDelete: 'cascade' }),
@@ -88,7 +102,9 @@ export const documentSigners = pgTable(
export const documentEvents = pgTable(
'document_events',
{
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
id: text('id')
.primaryKey()
.$defaultFn(() => crypto.randomUUID()),
documentId: text('document_id')
.notNull()
.references(() => documents.id, { onDelete: 'cascade' }),
@@ -100,16 +116,18 @@ export const documentEvents = pgTable(
},
(table) => [
index('idx_de_doc').on(table.documentId),
uniqueIndex('idx_de_dedup').on(table.documentId, table.signatureHash).where(
sql`${table.signatureHash} IS NOT NULL`
),
uniqueIndex('idx_de_dedup')
.on(table.documentId, table.signatureHash)
.where(sql`${table.signatureHash} IS NOT NULL`),
],
);
export const documentTemplates = pgTable(
'document_templates',
{
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
id: text('id')
.primaryKey()
.$defaultFn(() => crypto.randomUUID()),
portId: text('port_id')
.notNull()
.references(() => ports.id),
@@ -132,7 +150,9 @@ export const documentTemplates = pgTable(
export const formTemplates = pgTable(
'form_templates',
{
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
id: text('id')
.primaryKey()
.$defaultFn(() => crypto.randomUUID()),
portId: text('port_id')
.notNull()
.references(() => ports.id),
@@ -151,7 +171,9 @@ export const formTemplates = pgTable(
export const formSubmissions = pgTable(
'form_submissions',
{
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
id: text('id')
.primaryKey()
.$defaultFn(() => crypto.randomUUID()),
formTemplateId: text('form_template_id')
.notNull()
.references(() => formTemplates.id),