Move document search_vector from documents to document_versions

Now that title lives on document_versions, the full-text search vector
belongs there too. Drop the generated column and GIN index from
documents, recreate them on document_versions, and update the document
filter to query the latest version's search_vector.

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2026-04-07 18:49:18 +02:00
parent 221afd8b8d
commit eb6c06e683
2 changed files with 18 additions and 1 deletions

View File

@@ -16,3 +16,14 @@
ALTER TABLE documents ALTER COLUMN title DROP NOT NULL;
ALTER TABLE documents DROP COLUMN description;
-- Move search_vector from documents to document_versions.
DROP INDEX documents_search_idx;
ALTER TABLE documents DROP COLUMN search_vector;
ALTER TABLE document_versions ADD COLUMN search_vector tsvector
GENERATED ALWAYS AS (
to_tsvector('simple', COALESCE(title, ''))
) STORED;
CREATE INDEX document_versions_search_idx ON document_versions USING gin(search_vector);