From 9da416dbe44f5c219161952ab3fc6deda452e409 Mon Sep 17 00:00:00 2001 From: trifonovt <87468028+TihomirTrifonov@users.noreply.github.com> Date: Mon, 18 May 2026 14:04:35 +0200 Subject: [PATCH] Align search migrations and test schemas --- .../V10__search_slice2_generic_search_support.sql | 8 ++++---- .../db/migration/V11__doc_option_a_semantic_hardening.sql | 3 +++ .../V13__ted_projection_add_package_identifier.sql | 2 +- .../db/migration/V14__doc_search_slice1_support.sql | 8 ++++---- src/main/resources/db/migration/V1__initial_schema.sql | 2 +- .../dip/testsupport/AbstractSearchIntegrationTest.java | 8 ++++---- .../AbstractSemanticSearchIntegrationTest.java | 8 ++++---- .../AbstractTedStructuredSearchIntegrationTest.java | 8 ++++---- src/test/resources/sql/create-doc-search-test-schemas.sql | 2 +- 9 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/main/resources/db/migration/V10__search_slice2_generic_search_support.sql b/src/main/resources/db/migration/V10__search_slice2_generic_search_support.sql index f9c397e..e6e4858 100644 --- a/src/main/resources/db/migration/V10__search_slice2_generic_search_support.sql +++ b/src/main/resources/db/migration/V10__search_slice2_generic_search_support.sql @@ -1,7 +1,7 @@ -- Slice 1 + Slice 2 generic search support for DOC documents. -- Adds lexical-search support columns/indexes and pg_trgm extension. -CREATE EXTENSION IF NOT EXISTS pg_trgm with schema doc; +CREATE EXTENSION IF NOT EXISTS pg_trgm with schema public; ALTER TABLE DOC.doc_text_representation ADD COLUMN IF NOT EXISTS search_config VARCHAR(64); @@ -15,12 +15,12 @@ CREATE INDEX IF NOT EXISTS idx_doc_text_repr_search_vector CREATE INDEX IF NOT EXISTS idx_doc_document_title_trgm ON DOC.doc_document - USING GIN (title DOC.gin_trgm_ops); + USING GIN (title public.gin_trgm_ops); CREATE INDEX IF NOT EXISTS idx_doc_document_summary_trgm ON DOC.doc_document - USING GIN (summary DOC.gin_trgm_ops); + USING GIN (summary public.gin_trgm_ops); CREATE INDEX IF NOT EXISTS idx_doc_text_repr_text_trgm ON DOC.doc_text_representation - USING GIN (text_body DOC.gin_trgm_ops); + USING GIN (text_body public.gin_trgm_ops); diff --git a/src/main/resources/db/migration/V11__doc_option_a_semantic_hardening.sql b/src/main/resources/db/migration/V11__doc_option_a_semantic_hardening.sql index 675bc2e..bd73c87 100644 --- a/src/main/resources/db/migration/V11__doc_option_a_semantic_hardening.sql +++ b/src/main/resources/db/migration/V11__doc_option_a_semantic_hardening.sql @@ -5,6 +5,9 @@ ALTER TABLE DOC.doc_embedding ADD CONSTRAINT ck_doc_embedding_dimensions_positive CHECK (embedding_dimensions IS NULL OR embedding_dimensions > 0); +ALTER TABLE DOC.doc_embedding + ADD COLUMN IF NOT EXISTS embedding_vector public.vector; + DO $$ BEGIN IF NOT EXISTS ( diff --git a/src/main/resources/db/migration/V13__ted_projection_add_package_identifier.sql b/src/main/resources/db/migration/V13__ted_projection_add_package_identifier.sql index ba5be04..01b7fc2 100644 --- a/src/main/resources/db/migration/V13__ted_projection_add_package_identifier.sql +++ b/src/main/resources/db/migration/V13__ted_projection_add_package_identifier.sql @@ -2,7 +2,7 @@ -- This makes migration, audit, and repair flows package-aware without having to derive the -- package membership from source paths at query time. -SET search_path TO TED, DOC, public; +SET search_path TO ted, doc, public; ALTER TABLE IF EXISTS TED.ted_notice_projection ADD COLUMN IF NOT EXISTS package_identifier VARCHAR(20); diff --git a/src/main/resources/db/migration/V14__doc_search_slice1_support.sql b/src/main/resources/db/migration/V14__doc_search_slice1_support.sql index 863c71d..45f1d71 100644 --- a/src/main/resources/db/migration/V14__doc_search_slice1_support.sql +++ b/src/main/resources/db/migration/V14__doc_search_slice1_support.sql @@ -1,7 +1,7 @@ -- Slice 1 generic lexical search support. -- Adds PostgreSQL full-text and trigram search infrastructure for DOC-side search. -CREATE EXTENSION IF NOT EXISTS pg_trgm with schema doc; +CREATE EXTENSION IF NOT EXISTS pg_trgm with schema public; ALTER TABLE doc.doc_text_representation ADD COLUMN IF NOT EXISTS search_config VARCHAR(64); @@ -15,12 +15,12 @@ CREATE INDEX IF NOT EXISTS idx_doc_text_repr_search_vector CREATE INDEX IF NOT EXISTS idx_doc_document_title_trgm ON doc.doc_document - USING GIN (title doc.gin_trgm_ops); + USING GIN (title public.gin_trgm_ops); CREATE INDEX IF NOT EXISTS idx_doc_document_summary_trgm ON doc.doc_document - USING GIN (summary doc.gin_trgm_ops); + USING GIN (summary public.gin_trgm_ops); CREATE INDEX IF NOT EXISTS idx_doc_text_repr_text_trgm ON doc.doc_text_representation - USING GIN (text_body doc.gin_trgm_ops); + USING GIN (text_body public.gin_trgm_ops); diff --git a/src/main/resources/db/migration/V1__initial_schema.sql b/src/main/resources/db/migration/V1__initial_schema.sql index 11b0b65..7fedc8a 100644 --- a/src/main/resources/db/migration/V1__initial_schema.sql +++ b/src/main/resources/db/migration/V1__initial_schema.sql @@ -306,7 +306,7 @@ CREATE INDEX idx_doc_procedure_type ON procurement_document(procedure_type); CREATE INDEX idx_doc_cpv_codes ON procurement_document USING GIN(cpv_codes); -- Full-text search on textual content -CREATE INDEX idx_doc_text_content_trgm ON procurement_document USING GIN(text_content gin_trgm_ops); +CREATE INDEX idx_doc_text_content_trgm ON procurement_document USING GIN(text_content public.gin_trgm_ops); -- Vector similarity search using IVFFlat index (efficient for approximate nearest neighbor) -- Lists parameter: sqrt(number_of_vectors) for optimal performance diff --git a/src/test/java/at/procon/dip/testsupport/AbstractSearchIntegrationTest.java b/src/test/java/at/procon/dip/testsupport/AbstractSearchIntegrationTest.java index 1640fc5..6b4fd97 100644 --- a/src/test/java/at/procon/dip/testsupport/AbstractSearchIntegrationTest.java +++ b/src/test/java/at/procon/dip/testsupport/AbstractSearchIntegrationTest.java @@ -87,13 +87,13 @@ public abstract class AbstractSearchIntegrationTest { protected void ensureSearchColumnsAndIndexes() { jdbcTemplate.execute("CREATE SCHEMA IF NOT EXISTS doc"); - jdbcTemplate.execute("CREATE EXTENSION IF NOT EXISTS pg_trgm with schema doc"); + jdbcTemplate.execute("CREATE EXTENSION IF NOT EXISTS pg_trgm with schema public"); jdbcTemplate.execute("ALTER TABLE doc.doc_text_representation ADD COLUMN IF NOT EXISTS search_config VARCHAR(64)"); jdbcTemplate.execute("ALTER TABLE doc.doc_text_representation ADD COLUMN IF NOT EXISTS search_vector tsvector"); jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_doc_text_repr_search_vector_test ON doc.doc_text_representation USING GIN (search_vector)"); - jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_doc_document_title_trgm_test ON doc.doc_document USING GIN (title doc.gin_trgm_ops)"); - jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_doc_document_summary_trgm_test ON doc.doc_document USING GIN (summary doc.gin_trgm_ops)"); - jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_doc_text_repr_text_trgm_test ON doc.doc_text_representation USING GIN (text_body doc.gin_trgm_ops)"); + jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_doc_document_title_trgm_test ON doc.doc_document USING GIN (title public.gin_trgm_ops)"); + jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_doc_document_summary_trgm_test ON doc.doc_document USING GIN (summary public.gin_trgm_ops)"); + jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_doc_text_repr_text_trgm_test ON doc.doc_text_representation USING GIN (text_body public.gin_trgm_ops)"); } protected void cleanupDatabase() { diff --git a/src/test/java/at/procon/dip/testsupport/AbstractSemanticSearchIntegrationTest.java b/src/test/java/at/procon/dip/testsupport/AbstractSemanticSearchIntegrationTest.java index a94f385..b7933d3 100644 --- a/src/test/java/at/procon/dip/testsupport/AbstractSemanticSearchIntegrationTest.java +++ b/src/test/java/at/procon/dip/testsupport/AbstractSemanticSearchIntegrationTest.java @@ -121,14 +121,14 @@ public abstract class AbstractSemanticSearchIntegrationTest { } protected void ensureSearchColumnsAndIndexes() { - jdbcTemplate.execute("CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA doc"); + jdbcTemplate.execute("CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA public"); jdbcTemplate.execute("CREATE EXTENSION IF NOT EXISTS vector WITH SCHEMA public"); jdbcTemplate.execute("ALTER TABLE doc.doc_text_representation ADD COLUMN IF NOT EXISTS search_config VARCHAR(64)"); jdbcTemplate.execute("ALTER TABLE doc.doc_text_representation ADD COLUMN IF NOT EXISTS search_vector tsvector"); jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_doc_text_repr_search_vector_test ON doc.doc_text_representation USING GIN (search_vector)"); - jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_doc_document_title_trgm_test ON doc.doc_document USING GIN (title doc.gin_trgm_ops)"); - jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_doc_document_summary_trgm_test ON doc.doc_document USING GIN (summary doc.gin_trgm_ops)"); - jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_doc_text_repr_text_trgm_test ON doc.doc_text_representation USING GIN (text_body doc.gin_trgm_ops)"); + jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_doc_document_title_trgm_test ON doc.doc_document USING GIN (title public.gin_trgm_ops)"); + jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_doc_document_summary_trgm_test ON doc.doc_document USING GIN (summary public.gin_trgm_ops)"); + jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_doc_text_repr_text_trgm_test ON doc.doc_text_representation USING GIN (text_body public.gin_trgm_ops)"); jdbcTemplate.execute("ALTER TABLE doc.doc_embedding ADD COLUMN IF NOT EXISTS embedding_vector public.vector"); } diff --git a/src/test/java/at/procon/dip/testsupport/AbstractTedStructuredSearchIntegrationTest.java b/src/test/java/at/procon/dip/testsupport/AbstractTedStructuredSearchIntegrationTest.java index 5069069..7b4358f 100644 --- a/src/test/java/at/procon/dip/testsupport/AbstractTedStructuredSearchIntegrationTest.java +++ b/src/test/java/at/procon/dip/testsupport/AbstractTedStructuredSearchIntegrationTest.java @@ -82,13 +82,13 @@ public abstract class AbstractTedStructuredSearchIntegrationTest { protected void ensureSearchColumnsAndIndexes() { jdbcTemplate.execute("CREATE SCHEMA IF NOT EXISTS doc"); jdbcTemplate.execute("CREATE SCHEMA IF NOT EXISTS ted"); - jdbcTemplate.execute("CREATE EXTENSION IF NOT EXISTS pg_trgm with schema doc"); + jdbcTemplate.execute("CREATE EXTENSION IF NOT EXISTS pg_trgm with schema public"); jdbcTemplate.execute("ALTER TABLE doc.doc_text_representation ADD COLUMN IF NOT EXISTS search_config VARCHAR(64)"); jdbcTemplate.execute("ALTER TABLE doc.doc_text_representation ADD COLUMN IF NOT EXISTS search_vector tsvector"); jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_doc_text_repr_search_vector_test ON doc.doc_text_representation USING GIN (search_vector)"); - jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_doc_document_title_trgm_test ON doc.doc_document USING GIN (title doc.gin_trgm_ops)"); - jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_doc_document_summary_trgm_test ON doc.doc_document USING GIN (summary doc.gin_trgm_ops)"); - jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_doc_text_repr_text_trgm_test ON doc.doc_text_representation USING GIN (text_body doc.gin_trgm_ops)"); + jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_doc_document_title_trgm_test ON doc.doc_document USING GIN (title public.gin_trgm_ops)"); + jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_doc_document_summary_trgm_test ON doc.doc_document USING GIN (summary public.gin_trgm_ops)"); + jdbcTemplate.execute("CREATE INDEX IF NOT EXISTS idx_doc_text_repr_text_trgm_test ON doc.doc_text_representation USING GIN (text_body public.gin_trgm_ops)"); } protected void cleanupDatabase() { diff --git a/src/test/resources/sql/create-doc-search-test-schemas.sql b/src/test/resources/sql/create-doc-search-test-schemas.sql index d2f36a7..6a3af79 100644 --- a/src/test/resources/sql/create-doc-search-test-schemas.sql +++ b/src/test/resources/sql/create-doc-search-test-schemas.sql @@ -1,3 +1,3 @@ CREATE SCHEMA IF NOT EXISTS DOC; CREATE SCHEMA IF NOT EXISTS TED; -CREATE EXTENSION IF NOT EXISTS pg_trgm with schema doc; +CREATE EXTENSION IF NOT EXISTS pg_trgm with schema public;