Update plugins/catalog-backend/migrations/20260214000000_search_fk_final_entities.js

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2026-03-11 16:19:19 +01:00
committed by GitHub
parent 34af7b4551
commit 2b87d22ad4
@@ -71,10 +71,14 @@ async function batchDeleteOrphansMysql(knex, refTable) {
* to final_entities(entity_id). This allows search entries to reference
* final entities directly, with CASCADE delete when entities are removed.
*
* For PostgreSQL and MySQL, the migration is structured to minimize lock
* time on large tables by batch-deleting orphaned rows before any DDL.
* PostgreSQL additionally uses NOT VALID / VALIDATE CONSTRAINT to keep
* the AccessExclusiveLock duration minimal.
* On PostgreSQL, the migration first switches the foreign key to point at
* final_entities using a single ALTER TABLE with a NOT VALID constraint,
* then batch-deletes any pre-existing orphaned rows outside of DDL, and
* finally VALIDATEs the constraint to keep the AccessExclusiveLock window
* as short as possible.
*
* On MySQL, the migration batch-deletes orphaned rows in chunks around the
* foreign key change to reduce lock time on large tables.
*
* @param {import('knex').Knex} knex
*/