From 27d2d3f0a281c919269a188c32944a05db7e9a89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Sun, 10 May 2026 14:21:19 +0200 Subject: [PATCH] fix down migration + update SQL report MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The down migration now restores the previous index state (drops new indices, recreates the old search_key_value_idx and search_key_original_value_idx). Updated the SQL report to reflect the new index set. Co-Authored-By: Claude Opus 4.7 (1M context) Signed-off-by: Fredrik Adelöw --- ...20260510000000_search_indices_and_dedup.js | 43 +++++++++++++++++-- plugins/catalog-backend/report.sql.md | 5 ++- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/plugins/catalog-backend/migrations/20260510000000_search_indices_and_dedup.js b/plugins/catalog-backend/migrations/20260510000000_search_indices_and_dedup.js index e60e39a017..623c5bbfce 100644 --- a/plugins/catalog-backend/migrations/20260510000000_search_indices_and_dedup.js +++ b/plugins/catalog-backend/migrations/20260510000000_search_indices_and_dedup.js @@ -80,10 +80,45 @@ exports.up = async function up(knex) { /** * @param {import('knex').Knex} knex */ -exports.down = async function down(_knex) { - // Intentionally a no-op. The old non-covering indices are not worth - // recreating, and the UNIQUE constraint should not be removed since the - // code now relies on ON CONFLICT for correctness. +exports.down = async function down(knex) { + const client = knex.client.config.client; + + if (client.includes('pg')) { + // Remove the new indices and restore the old ones + await knex.raw( + 'DROP INDEX CONCURRENTLY IF EXISTS search_entity_key_value_idx', + ); + await knex.raw( + 'DROP INDEX CONCURRENTLY IF EXISTS search_key_value_entity_idx', + ); + await knex.raw( + 'DROP INDEX CONCURRENTLY IF EXISTS search_facets_covering_idx', + ); + await knex.raw( + 'CREATE INDEX CONCURRENTLY IF NOT EXISTS search_key_value_idx ON search (key, value)', + ); + await knex.raw( + 'CREATE INDEX CONCURRENTLY IF NOT EXISTS search_key_original_value_idx ON search (key, original_value)', + ); + } else if (client.includes('mysql')) { + await mysqlDropIndexIfExists(knex, 'search_entity_key_value_idx'); + await mysqlDropIndexIfExists(knex, 'search_key_value_entity_idx'); + await mysqlDropIndexIfExists(knex, 'search_facets_covering_idx'); + await knex.schema.alterTable('search', table => { + table.index(['key', 'value'], 'search_key_value_idx'); + table.index(['key', 'original_value'], 'search_key_original_value_idx'); + }); + } else { + await knex.raw('DROP INDEX IF EXISTS search_entity_key_value_idx'); + await knex.raw('DROP INDEX IF EXISTS search_key_value_entity_idx'); + await knex.raw('DROP INDEX IF EXISTS search_facets_covering_idx'); + await knex.raw( + 'CREATE INDEX IF NOT EXISTS search_key_value_idx ON search (key, value)', + ); + await knex.raw( + 'CREATE INDEX IF NOT EXISTS search_key_original_value_idx ON search (key, original_value)', + ); + } }; exports.config = { transaction: false }; diff --git a/plugins/catalog-backend/report.sql.md b/plugins/catalog-backend/report.sql.md index e23b250be8..0ea80db3f4 100644 --- a/plugins/catalog-backend/report.sql.md +++ b/plugins/catalog-backend/report.sql.md @@ -127,8 +127,9 @@ ### Indices - `search_entity_id_idx` (`entity_id`) -- `search_key_original_value_idx` (`key`, `original_value`) -- `search_key_value_idx` (`key`, `value`) +- `search_entity_key_value_idx` (`entity_id`, `key`, `value`) unique +- `search_facets_covering_idx` (`key`, `original_value`, `entity_id`) +- `search_key_value_entity_idx` (`key`, `value`, `entity_id`) ## Table `stitch_queue`