feat(schema): wire yacht, company, reservation relations in Drizzle

This commit is contained in:
Matt Ciaccio
2026-04-23 18:02:22 +02:00
parent 14dac2f3e1
commit 077ba5bf6b

View File

@@ -20,6 +20,18 @@ import {
// Interests
import { interests, interestNotes, interestTags } from './interests';
// Yachts
import { yachts, yachtOwnershipHistory, yachtNotes, yachtTags } from './yachts';
// Companies
import {
companies,
companyMemberships,
companyAddresses,
companyNotes,
companyTags,
} from './companies';
// Berths
import {
berths,
@@ -30,6 +42,9 @@ import {
berthTags,
} from './berths';
// Reservations
import { berthReservations } from './reservations';
// Documents
import {
files,
@@ -79,7 +94,10 @@ export const portsRelations = relations(ports, ({ many }) => ({
portRoleOverrides: many(portRoleOverrides),
clients: many(clients),
interests: many(interests),
yachts: many(yachts),
companies: many(companies),
berths: many(berths),
berthReservations: many(berthReservations),
documents: many(documents),
documentTemplates: many(documentTemplates),
formTemplates: many(formTemplates),
@@ -159,6 +177,8 @@ export const clientsRelations = relations(clients, ({ one, many }) => ({
scratchpadNotes: many(scratchpadNotes),
formSubmissions: many(formSubmissions),
addresses: many(clientAddresses),
companyMemberships: many(companyMemberships),
berthReservations: many(berthReservations),
}));
export const clientContactsRelations = relations(clientContacts, ({ one }) => ({
@@ -240,6 +260,10 @@ export const interestsRelations = relations(interests, ({ one, many }) => ({
fields: [interests.berthId],
references: [berths.id],
}),
yacht: one(yachts, {
fields: [interests.yachtId],
references: [yachts.id],
}),
notes: many(interestNotes),
tags: many(interestTags),
documents: many(documents),
@@ -266,6 +290,101 @@ export const interestTagsRelations = relations(interestTags, ({ one }) => ({
}),
}));
// ─── Yachts ───────────────────────────────────────────────────────────────────
export const yachtsRelations = relations(yachts, ({ one, many }) => ({
port: one(ports, {
fields: [yachts.portId],
references: [ports.id],
}),
ownershipHistory: many(yachtOwnershipHistory),
notes: many(yachtNotes),
tags: many(yachtTags),
interests: many(interests),
reservations: many(berthReservations),
documents: many(documents),
}));
export const yachtOwnershipHistoryRelations = relations(yachtOwnershipHistory, ({ one }) => ({
yacht: one(yachts, {
fields: [yachtOwnershipHistory.yachtId],
references: [yachts.id],
}),
}));
export const yachtNotesRelations = relations(yachtNotes, ({ one }) => ({
yacht: one(yachts, {
fields: [yachtNotes.yachtId],
references: [yachts.id],
}),
}));
export const yachtTagsRelations = relations(yachtTags, ({ one }) => ({
yacht: one(yachts, {
fields: [yachtTags.yachtId],
references: [yachts.id],
}),
tag: one(tags, {
fields: [yachtTags.tagId],
references: [tags.id],
}),
}));
// ─── Companies ────────────────────────────────────────────────────────────────
export const companiesRelations = relations(companies, ({ one, many }) => ({
port: one(ports, {
fields: [companies.portId],
references: [ports.id],
}),
memberships: many(companyMemberships),
addresses: many(companyAddresses),
notes: many(companyNotes),
tags: many(companyTags),
documents: many(documents),
files: many(files),
}));
export const companyMembershipsRelations = relations(companyMemberships, ({ one }) => ({
company: one(companies, {
fields: [companyMemberships.companyId],
references: [companies.id],
}),
client: one(clients, {
fields: [companyMemberships.clientId],
references: [clients.id],
}),
}));
export const companyAddressesRelations = relations(companyAddresses, ({ one }) => ({
company: one(companies, {
fields: [companyAddresses.companyId],
references: [companies.id],
}),
port: one(ports, {
fields: [companyAddresses.portId],
references: [ports.id],
}),
}));
export const companyNotesRelations = relations(companyNotes, ({ one }) => ({
company: one(companies, {
fields: [companyNotes.companyId],
references: [companies.id],
}),
}));
export const companyTagsRelations = relations(companyTags, ({ one }) => ({
company: one(companies, {
fields: [companyTags.companyId],
references: [companies.id],
}),
tag: one(tags, {
fields: [companyTags.tagId],
references: [tags.id],
}),
}));
// ─── Berths ───────────────────────────────────────────────────────────────────
export const berthsRelations = relations(berths, ({ one, many }) => ({
@@ -333,6 +452,35 @@ export const berthTagsRelations = relations(berthTags, ({ one }) => ({
}),
}));
// ─── Berth Reservations ───────────────────────────────────────────────────────
export const berthReservationsRelations = relations(berthReservations, ({ one }) => ({
berth: one(berths, {
fields: [berthReservations.berthId],
references: [berths.id],
}),
port: one(ports, {
fields: [berthReservations.portId],
references: [ports.id],
}),
client: one(clients, {
fields: [berthReservations.clientId],
references: [clients.id],
}),
yacht: one(yachts, {
fields: [berthReservations.yachtId],
references: [yachts.id],
}),
interest: one(interests, {
fields: [berthReservations.interestId],
references: [interests.id],
}),
contractFile: one(files, {
fields: [berthReservations.contractFileId],
references: [files.id],
}),
}));
// ─── Documents ────────────────────────────────────────────────────────────────
export const filesRelations = relations(files, ({ one, many }) => ({
@@ -344,6 +492,14 @@ export const filesRelations = relations(files, ({ one, many }) => ({
fields: [files.clientId],
references: [clients.id],
}),
yacht: one(yachts, {
fields: [files.yachtId],
references: [yachts.id],
}),
company: one(companies, {
fields: [files.companyId],
references: [companies.id],
}),
documentAsFile: many(documents, { relationName: 'file' }),
documentAsSignedFile: many(documents, { relationName: 'signed_file' }),
}));
@@ -371,6 +527,14 @@ export const documentsRelations = relations(documents, ({ one, many }) => ({
references: [files.id],
relationName: 'signed_file',
}),
yacht: one(yachts, {
fields: [documents.yachtId],
references: [yachts.id],
}),
company: one(companies, {
fields: [documents.companyId],
references: [companies.id],
}),
signers: many(documentSigners),
events: many(documentEvents),
}));