From bfca086e7be335a44fb129a61837b7186380c2d7 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Mon, 20 Mar 2023 22:17:07 +0100 Subject: [PATCH] only drop indexes if they exist --- .../20230320130345-fulltext-search-indexes.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/backend/src/db/migrations/20230320130345-fulltext-search-indexes.js b/backend/src/db/migrations/20230320130345-fulltext-search-indexes.js index 27fcc7db5..73040adf7 100644 --- a/backend/src/db/migrations/20230320130345-fulltext-search-indexes.js +++ b/backend/src/db/migrations/20230320130345-fulltext-search-indexes.js @@ -8,10 +8,19 @@ export async function up(next) { const transaction = session.beginTransaction() try { - // Drop all indexes because due to legacy code they might be set already - await transaction.run(`CALL db.index.fulltext.drop("user_fulltext_search")`) - await transaction.run(`CALL db.index.fulltext.drop("post_fulltext_search")`) - await transaction.run(`CALL db.index.fulltext.drop("tag_fulltext_search")`) + // Drop indexes if they exist because due to legacy code they might be set already + const indexesResponse = await transaction.run(`CALL db.indexes()`) + const indexes = indexesResponse.records.map((record) => record.get('indexName')) + console.log(indexes) + if(indexes.indexOf('user_fulltext_search') > -1){ + await transaction.run(`CALL db.index.fulltext.drop("user_fulltext_search")`) + } + if(indexes.indexOf('post_fulltext_search') > -1){ + await transaction.run(`CALL db.index.fulltext.drop("post_fulltext_search")`) + } + if(indexes.indexOf('tag_fulltext_search') > -1){ + await transaction.run(`CALL db.index.fulltext.drop("tag_fulltext_search")`) + } // Create indexes await transaction.run( `CALL db.index.fulltext.createNodeIndex("user_fulltext_search",["User"],["name", "slug"])`,