From 5231476c274e0569b0d96a1291325d3be5d8c7fb Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 5 Apr 2026 11:12:08 +0200 Subject: [PATCH] feat(transcription): add Flyway migrations for transcription blocks V18: transcription_blocks table with optimistic locking version column V19: transcription_block_versions for edit history capture V20: add block_id FK to document_comments for block-level threads Co-Authored-By: Claude Sonnet 4.6 --- .../migration/V18__add_transcription_blocks.sql | 16 ++++++++++++++++ .../V19__add_transcription_block_versions.sql | 9 +++++++++ .../migration/V20__add_block_id_to_comments.sql | 4 ++++ 3 files changed, 29 insertions(+) create mode 100644 backend/src/main/resources/db/migration/V18__add_transcription_blocks.sql create mode 100644 backend/src/main/resources/db/migration/V19__add_transcription_block_versions.sql create mode 100644 backend/src/main/resources/db/migration/V20__add_block_id_to_comments.sql diff --git a/backend/src/main/resources/db/migration/V18__add_transcription_blocks.sql b/backend/src/main/resources/db/migration/V18__add_transcription_blocks.sql new file mode 100644 index 00000000..03e5aaf8 --- /dev/null +++ b/backend/src/main/resources/db/migration/V18__add_transcription_blocks.sql @@ -0,0 +1,16 @@ +CREATE TABLE transcription_blocks ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + annotation_id UUID NOT NULL REFERENCES document_annotations(id) ON DELETE CASCADE, + document_id UUID NOT NULL REFERENCES documents(id) ON DELETE CASCADE, + text TEXT NOT NULL DEFAULT '', + label VARCHAR(200), + sort_order INTEGER NOT NULL DEFAULT 0, + version INTEGER NOT NULL DEFAULT 0, + created_by UUID REFERENCES app_users(id) ON DELETE SET NULL, + updated_by UUID REFERENCES app_users(id) ON DELETE SET NULL, + created_at TIMESTAMP NOT NULL DEFAULT now(), + updated_at TIMESTAMP NOT NULL DEFAULT now() +); + +CREATE INDEX idx_tb_document_sort ON transcription_blocks(document_id, sort_order); +CREATE INDEX idx_tb_annotation ON transcription_blocks(annotation_id); diff --git a/backend/src/main/resources/db/migration/V19__add_transcription_block_versions.sql b/backend/src/main/resources/db/migration/V19__add_transcription_block_versions.sql new file mode 100644 index 00000000..54df152c --- /dev/null +++ b/backend/src/main/resources/db/migration/V19__add_transcription_block_versions.sql @@ -0,0 +1,9 @@ +CREATE TABLE transcription_block_versions ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + block_id UUID NOT NULL REFERENCES transcription_blocks(id) ON DELETE CASCADE, + text TEXT NOT NULL, + changed_by UUID REFERENCES app_users(id) ON DELETE SET NULL, + changed_at TIMESTAMP NOT NULL DEFAULT now() +); + +CREATE INDEX idx_tbv_block ON transcription_block_versions(block_id, changed_at DESC); diff --git a/backend/src/main/resources/db/migration/V20__add_block_id_to_comments.sql b/backend/src/main/resources/db/migration/V20__add_block_id_to_comments.sql new file mode 100644 index 00000000..025091ec --- /dev/null +++ b/backend/src/main/resources/db/migration/V20__add_block_id_to_comments.sql @@ -0,0 +1,4 @@ +ALTER TABLE document_comments + ADD COLUMN block_id UUID REFERENCES transcription_blocks(id) ON DELETE CASCADE; + +CREATE INDEX idx_dc_block ON document_comments(block_id);