feat(schema): wire yacht, company, reservation relations in Drizzle
This commit is contained in:
@@ -20,6 +20,18 @@ import {
|
|||||||
// Interests
|
// Interests
|
||||||
import { interests, interestNotes, interestTags } from './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
|
// Berths
|
||||||
import {
|
import {
|
||||||
berths,
|
berths,
|
||||||
@@ -30,6 +42,9 @@ import {
|
|||||||
berthTags,
|
berthTags,
|
||||||
} from './berths';
|
} from './berths';
|
||||||
|
|
||||||
|
// Reservations
|
||||||
|
import { berthReservations } from './reservations';
|
||||||
|
|
||||||
// Documents
|
// Documents
|
||||||
import {
|
import {
|
||||||
files,
|
files,
|
||||||
@@ -79,7 +94,10 @@ export const portsRelations = relations(ports, ({ many }) => ({
|
|||||||
portRoleOverrides: many(portRoleOverrides),
|
portRoleOverrides: many(portRoleOverrides),
|
||||||
clients: many(clients),
|
clients: many(clients),
|
||||||
interests: many(interests),
|
interests: many(interests),
|
||||||
|
yachts: many(yachts),
|
||||||
|
companies: many(companies),
|
||||||
berths: many(berths),
|
berths: many(berths),
|
||||||
|
berthReservations: many(berthReservations),
|
||||||
documents: many(documents),
|
documents: many(documents),
|
||||||
documentTemplates: many(documentTemplates),
|
documentTemplates: many(documentTemplates),
|
||||||
formTemplates: many(formTemplates),
|
formTemplates: many(formTemplates),
|
||||||
@@ -159,6 +177,8 @@ export const clientsRelations = relations(clients, ({ one, many }) => ({
|
|||||||
scratchpadNotes: many(scratchpadNotes),
|
scratchpadNotes: many(scratchpadNotes),
|
||||||
formSubmissions: many(formSubmissions),
|
formSubmissions: many(formSubmissions),
|
||||||
addresses: many(clientAddresses),
|
addresses: many(clientAddresses),
|
||||||
|
companyMemberships: many(companyMemberships),
|
||||||
|
berthReservations: many(berthReservations),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const clientContactsRelations = relations(clientContacts, ({ one }) => ({
|
export const clientContactsRelations = relations(clientContacts, ({ one }) => ({
|
||||||
@@ -240,6 +260,10 @@ export const interestsRelations = relations(interests, ({ one, many }) => ({
|
|||||||
fields: [interests.berthId],
|
fields: [interests.berthId],
|
||||||
references: [berths.id],
|
references: [berths.id],
|
||||||
}),
|
}),
|
||||||
|
yacht: one(yachts, {
|
||||||
|
fields: [interests.yachtId],
|
||||||
|
references: [yachts.id],
|
||||||
|
}),
|
||||||
notes: many(interestNotes),
|
notes: many(interestNotes),
|
||||||
tags: many(interestTags),
|
tags: many(interestTags),
|
||||||
documents: many(documents),
|
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 ───────────────────────────────────────────────────────────────────
|
// ─── Berths ───────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
export const berthsRelations = relations(berths, ({ one, many }) => ({
|
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 ────────────────────────────────────────────────────────────────
|
// ─── Documents ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
export const filesRelations = relations(files, ({ one, many }) => ({
|
export const filesRelations = relations(files, ({ one, many }) => ({
|
||||||
@@ -344,6 +492,14 @@ export const filesRelations = relations(files, ({ one, many }) => ({
|
|||||||
fields: [files.clientId],
|
fields: [files.clientId],
|
||||||
references: [clients.id],
|
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' }),
|
documentAsFile: many(documents, { relationName: 'file' }),
|
||||||
documentAsSignedFile: many(documents, { relationName: 'signed_file' }),
|
documentAsSignedFile: many(documents, { relationName: 'signed_file' }),
|
||||||
}));
|
}));
|
||||||
@@ -371,6 +527,14 @@ export const documentsRelations = relations(documents, ({ one, many }) => ({
|
|||||||
references: [files.id],
|
references: [files.id],
|
||||||
relationName: 'signed_file',
|
relationName: 'signed_file',
|
||||||
}),
|
}),
|
||||||
|
yacht: one(yachts, {
|
||||||
|
fields: [documents.yachtId],
|
||||||
|
references: [yachts.id],
|
||||||
|
}),
|
||||||
|
company: one(companies, {
|
||||||
|
fields: [documents.companyId],
|
||||||
|
references: [companies.id],
|
||||||
|
}),
|
||||||
signers: many(documentSigners),
|
signers: many(documentSigners),
|
||||||
events: many(documentEvents),
|
events: many(documentEvents),
|
||||||
}));
|
}));
|
||||||
|
|||||||
Reference in New Issue
Block a user