feat(schema): add yachtId to interests and berth_waiting_list

This commit is contained in:
Matt Ciaccio
2026-04-23 17:57:29 +02:00
parent 88a87afa77
commit d43298a74e
5 changed files with 8520 additions and 20 deletions

View File

@@ -0,0 +1,3 @@
ALTER TABLE "berth_waiting_list" ADD COLUMN "yacht_id" text;--> statement-breakpoint
ALTER TABLE "interests" ADD COLUMN "yacht_id" text;--> statement-breakpoint
CREATE INDEX "idx_interests_yacht" ON "interests" USING btree ("yacht_id");

File diff suppressed because it is too large Load Diff

View File

@@ -36,6 +36,13 @@
"when": 1776959707066,
"tag": "0004_nasty_warstar",
"breakpoints": true
},
{
"idx": 5,
"version": "7",
"when": 1776959832091,
"tag": "0005_stale_kronos",
"breakpoints": true
}
]
}

View File

@@ -17,7 +17,9 @@ import { clients } from './clients';
export const berths = pgTable(
'berths',
{
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
id: text('id')
.primaryKey()
.$defaultFn(() => crypto.randomUUID()),
portId: text('port_id')
.notNull()
.references(() => ports.id),
@@ -70,7 +72,9 @@ export const berths = pgTable(
export const berthMapData = pgTable(
'berth_map_data',
{
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
id: text('id')
.primaryKey()
.$defaultFn(() => crypto.randomUUID()),
berthId: text('berth_id')
.notNull()
.unique()
@@ -89,7 +93,9 @@ export const berthMapData = pgTable(
export const berthRecommendations = pgTable(
'berth_recommendations',
{
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
id: text('id')
.primaryKey()
.$defaultFn(() => crypto.randomUUID()),
interestId: text('interest_id').notNull(), // references interests.id
berthId: text('berth_id')
.notNull()
@@ -109,13 +115,16 @@ export const berthRecommendations = pgTable(
export const berthWaitingList = pgTable(
'berth_waiting_list',
{
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
id: text('id')
.primaryKey()
.$defaultFn(() => crypto.randomUUID()),
berthId: text('berth_id')
.notNull()
.references(() => berths.id, { onDelete: 'cascade' }),
clientId: text('client_id')
.notNull()
.references(() => clients.id, { onDelete: 'cascade' }),
yachtId: text('yacht_id'), // FK added via relation; nullable (waiting for this yacht)
position: integer('position').notNull(),
priority: text('priority').notNull().default('normal'), // normal, high
notifyPref: text('notify_pref').default('email'), // email, in_app, both
@@ -131,7 +140,9 @@ export const berthWaitingList = pgTable(
export const berthMaintenanceLog = pgTable(
'berth_maintenance_log',
{
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
id: text('id')
.primaryKey()
.$defaultFn(() => crypto.randomUUID()),
berthId: text('berth_id')
.notNull()
.references(() => berths.id, { onDelete: 'cascade' }),
@@ -149,10 +160,7 @@ export const berthMaintenanceLog = pgTable(
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
},
(table) => [
index('idx_bml_berth').on(table.berthId),
index('idx_bml_port').on(table.portId),
],
(table) => [index('idx_bml_berth').on(table.berthId), index('idx_bml_port').on(table.portId)],
);
export const berthTags = pgTable(

View File

@@ -1,12 +1,4 @@
import {
pgTable,
text,
boolean,
integer,
timestamp,
primaryKey,
index,
} from 'drizzle-orm/pg-core';
import { pgTable, text, boolean, integer, timestamp, primaryKey, index } from 'drizzle-orm/pg-core';
import { ports } from './ports';
import { clients } from './clients';
@@ -15,7 +7,9 @@ import { clients } from './clients';
export const interests = pgTable(
'interests',
{
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
id: text('id')
.primaryKey()
.$defaultFn(() => crypto.randomUUID()),
portId: text('port_id')
.notNull()
.references(() => ports.id),
@@ -23,6 +17,7 @@ export const interests = pgTable(
.notNull()
.references(() => clients.id),
berthId: text('berth_id'), // nullable — FK to berths defined in berths.ts, added via relation
yachtId: text('yacht_id'), // FK added via relation; nullable until pipeline leaves 'open'
pipelineStage: text('pipeline_stage').notNull().default('open'),
leadCategory: text('lead_category'), // general_interest, specific_qualified, hot_lead
source: text('source'), // website, manual, referral, broker
@@ -50,6 +45,7 @@ export const interests = pgTable(
index('idx_interests_port').on(table.portId),
index('idx_interests_client').on(table.clientId),
index('idx_interests_berth').on(table.berthId),
index('idx_interests_yacht').on(table.yachtId),
index('idx_interests_stage').on(table.portId, table.pipelineStage),
index('idx_interests_archived').on(table.portId, table.archivedAt),
],
@@ -58,7 +54,9 @@ export const interests = pgTable(
export const interestNotes = pgTable(
'interest_notes',
{
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
id: text('id')
.primaryKey()
.$defaultFn(() => crypto.randomUUID()),
interestId: text('interest_id')
.notNull()
.references(() => interests.id, { onDelete: 'cascade' }),