From b8f94260e0cb974747151efad16b308a84e692fa Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 6 Sep 2023 13:32:25 +0530 Subject: [PATCH] fix: exclude composite indexes from list Signed-off-by: Pranav C --- .../ncXcdbLTARIndexUpgrader.ts | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/nocodb/src/version-upgrader/ncXcdbLTARIndexUpgrader.ts b/packages/nocodb/src/version-upgrader/ncXcdbLTARIndexUpgrader.ts index 997869fc85..0cc10f0428 100644 --- a/packages/nocodb/src/version-upgrader/ncXcdbLTARIndexUpgrader.ts +++ b/packages/nocodb/src/version-upgrader/ncXcdbLTARIndexUpgrader.ts @@ -50,7 +50,8 @@ async function upgradeModelRelationsIndex({ } switch (colOptions.type) { - case RelationTypes.HAS_MANY: + // use belongs to since child column belongs to current table in that case + case RelationTypes.BELONGS_TO: { // const parentCol = await colOptions.getParentColumn(ncMeta); const childCol = await colOptions.getChildColumn(ncMeta); @@ -60,10 +61,7 @@ async function upgradeModelRelationsIndex({ // check index already exists or not const indexExists = indexes.find((index) => { - return ( - index.cn === childCol.column_name && - index.key_name === childCol.column_name - ); + return index.cn === childCol.column_name; }); if (indexExists) { @@ -108,11 +106,21 @@ async function upgradeBaseRelations({ const indexes = await sqlClient.indexList({ tn: model.table_name, }); + const indexList = indexes.data?.list ?? []; + + // exclude composite indexes + const filteredIndexList = indexList.filter((indexObj, i) => { + return indexList.every((indexObj2, j) => { + if (i === j) return true; + return indexObj2.key_name !== indexObj.key_name; + }); + }); + await upgradeModelRelationsIndex({ ncMeta, model: new Model(model), sqlClient, - indexes: indexes.data.list, + indexes: filteredIndexList, }); logger.log(`Upgraded model '${model.title}'`); }