feat(journeyitem): V74 — partial unique index + note-length CHECK as atomic backstops
The append dedup guard was check-then-insert: two concurrent appends of the same document both pass exists() and both insert. The partial unique index on (geschichte_id, document_id) WHERE document_id IS NOT NULL closes the race; append saveAndFlush-es and maps the DataIntegrityViolationException to the same 409 JOURNEY_DOCUMENT_ALREADY_ADDED as the friendly pre-check. The CHECK on note length pins the 2000-char contract in the schema, mirroring chk_text_length on transcription_blocks. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -377,9 +377,10 @@ package "Supporting" {
|
||||
geschichte_id : UUID <<FK>>
|
||||
document_id : UUID <<FK>>
|
||||
position : INTEGER NOT NULL CHECK (position > 0)
|
||||
note : TEXT
|
||||
note : TEXT CHECK (length <= 2000)
|
||||
==
|
||||
UNIQUE (geschichte_id, position) DEFERRABLE INITIALLY DEFERRED
|
||||
UNIQUE (geschichte_id, document_id) WHERE document_id IS NOT NULL
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -131,5 +131,6 @@ geschichten_persons }o--|| geschichten : geschichte_id
|
||||
geschichten_persons }o--|| persons : person_id
|
||||
journey_items }o--|| geschichten : geschichte_id (ON DELETE CASCADE)
|
||||
journey_items }o--o| documents : document_id (ON DELETE SET NULL)
|
||||
note right of journey_items : partial UNIQUE (geschichte_id, document_id)\nWHERE document_id IS NOT NULL (V74)
|
||||
|
||||
@enduml
|
||||
|
||||
Reference in New Issue
Block a user