From 22fe9600a14d38e8264b45e3a8704b6d21d3862b Mon Sep 17 00:00:00 2001 From: Marcel Date: Tue, 7 Apr 2026 13:02:51 +0200 Subject: [PATCH] feat(migration): V21 add person_name_aliases table with pg_trgm indexes Creates the alias table for historical name changes (marriage, widowhood, etc.) and adds GIN trigram indexes on both the new alias table and the existing persons table for substring search. Co-Authored-By: Claude Sonnet 4.6 --- .../V21__add_person_name_aliases.sql | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 backend/src/main/resources/db/migration/V21__add_person_name_aliases.sql diff --git a/backend/src/main/resources/db/migration/V21__add_person_name_aliases.sql b/backend/src/main/resources/db/migration/V21__add_person_name_aliases.sql new file mode 100644 index 00000000..1c7e706e --- /dev/null +++ b/backend/src/main/resources/db/migration/V21__add_person_name_aliases.sql @@ -0,0 +1,22 @@ +-- Enable pg_trgm for substring search via GIN indexes +CREATE EXTENSION IF NOT EXISTS pg_trgm; + +-- Historical name aliases for persons (marriage, widowhood, etc.) +CREATE TABLE person_name_aliases ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + person_id UUID NOT NULL REFERENCES persons(id) ON DELETE CASCADE, + last_name VARCHAR(255) NOT NULL, + first_name VARCHAR(255), + type VARCHAR(50) NOT NULL, + sort_order INTEGER NOT NULL DEFAULT 0, + created_at TIMESTAMPTZ DEFAULT now() +); + +-- Indexes on alias table +CREATE INDEX idx_aliases_person_id ON person_name_aliases(person_id); +CREATE INDEX idx_aliases_last_name_trgm ON person_name_aliases USING GIN (lower(last_name) gin_trgm_ops); + +-- Retroactive GIN trigram indexes on existing persons table for substring search +CREATE INDEX idx_persons_first_name_trgm ON persons USING GIN (lower(first_name) gin_trgm_ops); +CREATE INDEX idx_persons_last_name_trgm ON persons USING GIN (lower(last_name) gin_trgm_ops); +CREATE INDEX idx_persons_alias_trgm ON persons USING GIN (lower(alias) gin_trgm_ops);