db: Foreign Keys für blocker- und Tageseintrag-Verweise (Migration 0017)

Bisher reine uuid-Spalten ohne referenzielle Integritaet -> Orphan-Risiko, wenn
das Ziel geloescht wird. Jetzt echte FKs mit ON DELETE SET NULL:

- day_entry.blocker_id -> blocker
- blocker.area_id -> area
- blocker.project_id -> project

Migration bereinigt vorab verwaiste IDs (UPDATE ... SET NULL), damit ADD
CONSTRAINT auf Altdaten nicht bricht. Verifiziert: alle 18 Migrationen laufen
gegen frische Postgres 16 durch, FKs angelegt.

(todo.bezug_id / time_entry.bezug_id bleiben FK-frei: echt polymorph ueber
bezug_kind project/deal/campaign — kein einzelner FK moeglich.)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Raffael SheikhandClaude Opus 4.8 committed 2026-06-07 12:01:24 +02:00
1 parent ff0a15b94e
commit 9bae1702aa
4 files changed
+3362 -3

No files matched your search

+3 -3
View File
@@ -231,7 +231,7 @@ export const dayEntry = pgTable(
ampel: text('ampel', { enum: ['green', 'amber', 'red'] }),
trend: text('trend', { enum: ['besser', 'gleich', 'schlechter'] }),
url: text('url'),
blockerId: uuid('blocker_id'),
blockerId: uuid('blocker_id').references(() => blocker.id, { onDelete: 'set null' }),
editLockedAt: timestamp('edit_locked_at', { withTimezone: true }),
publishedAt: timestamp('published_at', { withTimezone: true }),
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
@@ -442,8 +442,8 @@ export const blocker = pgTable(
.primaryKey(),
title: text('title').notNull(),
description: text('description'),
areaId: uuid('area_id'),
projectId: uuid('project_id'),
areaId: uuid('area_id').references(() => area.id, { onDelete: 'set null' }),
projectId: uuid('project_id').references(() => project.id, { onDelete: 'set null' }),
ownerUserId: uuid('owner_user_id').references(() => user.id, { onDelete: 'set null' }),
openedBy: uuid('opened_by')
.notNull()