feat(schema): add yachtId to interests and berth_waiting_list
This commit is contained in:
3
src/lib/db/migrations/0005_stale_kronos.sql
Normal file
3
src/lib/db/migrations/0005_stale_kronos.sql
Normal 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");
|
||||||
8484
src/lib/db/migrations/meta/0005_snapshot.json
Normal file
8484
src/lib/db/migrations/meta/0005_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -36,6 +36,13 @@
|
|||||||
"when": 1776959707066,
|
"when": 1776959707066,
|
||||||
"tag": "0004_nasty_warstar",
|
"tag": "0004_nasty_warstar",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 5,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1776959832091,
|
||||||
|
"tag": "0005_stale_kronos",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ import { clients } from './clients';
|
|||||||
export const berths = pgTable(
|
export const berths = pgTable(
|
||||||
'berths',
|
'berths',
|
||||||
{
|
{
|
||||||
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
id: text('id')
|
||||||
|
.primaryKey()
|
||||||
|
.$defaultFn(() => crypto.randomUUID()),
|
||||||
portId: text('port_id')
|
portId: text('port_id')
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => ports.id),
|
.references(() => ports.id),
|
||||||
@@ -70,7 +72,9 @@ export const berths = pgTable(
|
|||||||
export const berthMapData = pgTable(
|
export const berthMapData = pgTable(
|
||||||
'berth_map_data',
|
'berth_map_data',
|
||||||
{
|
{
|
||||||
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
id: text('id')
|
||||||
|
.primaryKey()
|
||||||
|
.$defaultFn(() => crypto.randomUUID()),
|
||||||
berthId: text('berth_id')
|
berthId: text('berth_id')
|
||||||
.notNull()
|
.notNull()
|
||||||
.unique()
|
.unique()
|
||||||
@@ -89,7 +93,9 @@ export const berthMapData = pgTable(
|
|||||||
export const berthRecommendations = pgTable(
|
export const berthRecommendations = pgTable(
|
||||||
'berth_recommendations',
|
'berth_recommendations',
|
||||||
{
|
{
|
||||||
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
id: text('id')
|
||||||
|
.primaryKey()
|
||||||
|
.$defaultFn(() => crypto.randomUUID()),
|
||||||
interestId: text('interest_id').notNull(), // references interests.id
|
interestId: text('interest_id').notNull(), // references interests.id
|
||||||
berthId: text('berth_id')
|
berthId: text('berth_id')
|
||||||
.notNull()
|
.notNull()
|
||||||
@@ -109,13 +115,16 @@ export const berthRecommendations = pgTable(
|
|||||||
export const berthWaitingList = pgTable(
|
export const berthWaitingList = pgTable(
|
||||||
'berth_waiting_list',
|
'berth_waiting_list',
|
||||||
{
|
{
|
||||||
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
id: text('id')
|
||||||
|
.primaryKey()
|
||||||
|
.$defaultFn(() => crypto.randomUUID()),
|
||||||
berthId: text('berth_id')
|
berthId: text('berth_id')
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => berths.id, { onDelete: 'cascade' }),
|
.references(() => berths.id, { onDelete: 'cascade' }),
|
||||||
clientId: text('client_id')
|
clientId: text('client_id')
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => clients.id, { onDelete: 'cascade' }),
|
.references(() => clients.id, { onDelete: 'cascade' }),
|
||||||
|
yachtId: text('yacht_id'), // FK added via relation; nullable (waiting for this yacht)
|
||||||
position: integer('position').notNull(),
|
position: integer('position').notNull(),
|
||||||
priority: text('priority').notNull().default('normal'), // normal, high
|
priority: text('priority').notNull().default('normal'), // normal, high
|
||||||
notifyPref: text('notify_pref').default('email'), // email, in_app, both
|
notifyPref: text('notify_pref').default('email'), // email, in_app, both
|
||||||
@@ -131,7 +140,9 @@ export const berthWaitingList = pgTable(
|
|||||||
export const berthMaintenanceLog = pgTable(
|
export const berthMaintenanceLog = pgTable(
|
||||||
'berth_maintenance_log',
|
'berth_maintenance_log',
|
||||||
{
|
{
|
||||||
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
id: text('id')
|
||||||
|
.primaryKey()
|
||||||
|
.$defaultFn(() => crypto.randomUUID()),
|
||||||
berthId: text('berth_id')
|
berthId: text('berth_id')
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => berths.id, { onDelete: 'cascade' }),
|
.references(() => berths.id, { onDelete: 'cascade' }),
|
||||||
@@ -149,10 +160,7 @@ export const berthMaintenanceLog = pgTable(
|
|||||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||||
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
||||||
},
|
},
|
||||||
(table) => [
|
(table) => [index('idx_bml_berth').on(table.berthId), index('idx_bml_port').on(table.portId)],
|
||||||
index('idx_bml_berth').on(table.berthId),
|
|
||||||
index('idx_bml_port').on(table.portId),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
export const berthTags = pgTable(
|
export const berthTags = pgTable(
|
||||||
|
|||||||
@@ -1,12 +1,4 @@
|
|||||||
import {
|
import { pgTable, text, boolean, integer, timestamp, primaryKey, index } from 'drizzle-orm/pg-core';
|
||||||
pgTable,
|
|
||||||
text,
|
|
||||||
boolean,
|
|
||||||
integer,
|
|
||||||
timestamp,
|
|
||||||
primaryKey,
|
|
||||||
index,
|
|
||||||
} from 'drizzle-orm/pg-core';
|
|
||||||
import { ports } from './ports';
|
import { ports } from './ports';
|
||||||
import { clients } from './clients';
|
import { clients } from './clients';
|
||||||
|
|
||||||
@@ -15,7 +7,9 @@ import { clients } from './clients';
|
|||||||
export const interests = pgTable(
|
export const interests = pgTable(
|
||||||
'interests',
|
'interests',
|
||||||
{
|
{
|
||||||
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
id: text('id')
|
||||||
|
.primaryKey()
|
||||||
|
.$defaultFn(() => crypto.randomUUID()),
|
||||||
portId: text('port_id')
|
portId: text('port_id')
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => ports.id),
|
.references(() => ports.id),
|
||||||
@@ -23,6 +17,7 @@ export const interests = pgTable(
|
|||||||
.notNull()
|
.notNull()
|
||||||
.references(() => clients.id),
|
.references(() => clients.id),
|
||||||
berthId: text('berth_id'), // nullable — FK to berths defined in berths.ts, added via relation
|
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'),
|
pipelineStage: text('pipeline_stage').notNull().default('open'),
|
||||||
leadCategory: text('lead_category'), // general_interest, specific_qualified, hot_lead
|
leadCategory: text('lead_category'), // general_interest, specific_qualified, hot_lead
|
||||||
source: text('source'), // website, manual, referral, broker
|
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_port').on(table.portId),
|
||||||
index('idx_interests_client').on(table.clientId),
|
index('idx_interests_client').on(table.clientId),
|
||||||
index('idx_interests_berth').on(table.berthId),
|
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_stage').on(table.portId, table.pipelineStage),
|
||||||
index('idx_interests_archived').on(table.portId, table.archivedAt),
|
index('idx_interests_archived').on(table.portId, table.archivedAt),
|
||||||
],
|
],
|
||||||
@@ -58,7 +54,9 @@ export const interests = pgTable(
|
|||||||
export const interestNotes = pgTable(
|
export const interestNotes = pgTable(
|
||||||
'interest_notes',
|
'interest_notes',
|
||||||
{
|
{
|
||||||
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
id: text('id')
|
||||||
|
.primaryKey()
|
||||||
|
.$defaultFn(() => crypto.randomUUID()),
|
||||||
interestId: text('interest_id')
|
interestId: text('interest_id')
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => interests.id, { onDelete: 'cascade' }),
|
.references(() => interests.id, { onDelete: 'cascade' }),
|
||||||
|
|||||||
Reference in New Issue
Block a user