diff --git a/server/migrations/20261112120000-add-pending-created-at-index-to-import-tasks.js b/server/migrations/20261112120000-add-pending-created-at-index-to-import-tasks.js new file mode 100644 index 0000000000..a3241f42fd --- /dev/null +++ b/server/migrations/20261112120000-add-pending-created-at-index-to-import-tasks.js @@ -0,0 +1,17 @@ +"use strict"; + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + async up(queryInterface) { + // Covers the scan for stuck import tasks, which pages by createdAt. + await queryInterface.sequelize.query( + `CREATE INDEX CONCURRENTLY IF NOT EXISTS "import_tasks_pending_created_at" ON "import_tasks" ("createdAt", "id") WHERE "state" IN ('created', 'in_progress');` + ); + }, + + async down(queryInterface) { + await queryInterface.sequelize.query( + 'DROP INDEX CONCURRENTLY IF EXISTS "import_tasks_pending_created_at";' + ); + }, +};