feat(db): tighten chk_system_folder_shape, add recommender FK + composite indexes

- Fix A5: chk_system_folder_shape NULL escape
- Fix Audit 17 G-I4: berthRecommendations.interestId FK with cascade
- Add (port_id, client_id) / (port_id, company_id) / (port_id, yacht_id) composite indexes on files + documents for aggregated-projection performance

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-11 13:47:52 +02:00
parent 0804944647
commit 1b00c8a7a2
3 changed files with 110 additions and 1 deletions

View File

@@ -14,6 +14,7 @@ import {
import { ports } from './ports';
import { clients } from './clients';
import { yachts } from './yachts';
import { interests } from './interests';
export const berths = pgTable(
'berths',
@@ -131,7 +132,9 @@ export const berthRecommendations = pgTable(
id: text('id')
.primaryKey()
.$defaultFn(() => crypto.randomUUID()),
interestId: text('interest_id').notNull(), // references interests.id
interestId: text('interest_id')
.notNull()
.references(() => interests.id, { onDelete: 'cascade' }),
berthId: text('berth_id')
.notNull()
.references(() => berths.id, { onDelete: 'cascade' }),