diff --git a/backend/src/main/resources/db/migration/V56__add_transcription_block_mentioned_persons.sql b/backend/src/main/resources/db/migration/V56__add_transcription_block_mentioned_persons.sql new file mode 100644 index 00000000..80a44ef4 --- /dev/null +++ b/backend/src/main/resources/db/migration/V56__add_transcription_block_mentioned_persons.sql @@ -0,0 +1,25 @@ +-- Sidecar table for @-mentions inside transcription_blocks.text. +-- Each row is one (block_id, person_id, display_name) tuple emitted by the +-- typeahead in the transcription editor. block.text contains the literal +-- "@DisplayName" — the UUID lives only here so historical text stays clean. +-- +-- Schema choice: child table via @ElementCollection (mirrors the established +-- UserGroup.permissions / group_permissions pattern), NOT JSONB. The "show +-- all blocks mentioning person X" query on the person detail page joins on +-- the indexed person_id column — equally fast as JSONB GIN containment, no +-- new dependency. document_comments.comment_mentions stays as a many-to-many +-- to AppUser; the divergence is intentional: Person mentions need lazy +-- degradation when a person is deleted (no FK), while user mentions don't. +-- +-- No FK on person_id: when a Person is deleted we want @Auguste Raddatz to +-- remain visible as plain unlinked text inside the transcription rather than +-- vanishing or cascade-deleting the block. + +CREATE TABLE transcription_block_mentioned_persons ( + block_id UUID NOT NULL REFERENCES transcription_blocks(id) ON DELETE CASCADE, + person_id UUID NOT NULL, + display_name VARCHAR(200) NOT NULL +); + +CREATE INDEX idx_tbmp_person_id ON transcription_block_mentioned_persons(person_id); +CREATE INDEX idx_tbmp_block_id ON transcription_block_mentioned_persons(block_id);