fix down migration + update SQL report
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) <noreply@anthropic.com> Signed-off-by: Fredrik Adelöw <freben@spotify.com>
This commit is contained in:
@@ -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 };
|
||||
|
||||
@@ -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`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user