From 7ca13e862d47e7144c7d9df453956fb7b0301181 Mon Sep 17 00:00:00 2001 From: Mert E Date: Tue, 28 May 2024 16:10:24 +0300 Subject: [PATCH] fix: add order by to comment migration (#8598) * fix: add order by to comment migration * fix: handle corner case for migration --- .../src/meta/migrations/v2/nc_047_comment_migration.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/nocodb/src/meta/migrations/v2/nc_047_comment_migration.ts b/packages/nocodb/src/meta/migrations/v2/nc_047_comment_migration.ts index ff6a0178a4..4d7d8152a6 100644 --- a/packages/nocodb/src/meta/migrations/v2/nc_047_comment_migration.ts +++ b/packages/nocodb/src/meta/migrations/v2/nc_047_comment_migration.ts @@ -12,6 +12,8 @@ const up = async (knex: Knex) => { let fetchNextBatch = true; + const insertedIds = new Set(); + for (let offset = 0; fetchNextBatch; offset += READ_BATCH_SIZE) { const rows = await knex .select( @@ -33,6 +35,7 @@ const up = async (knex: Knex) => { `${MetaTable.AUDIT}.user`, `${MetaTable.USERS}.email`, ) + .orderBy(`${MetaTable.AUDIT}.id`) .offset(offset) // increase limit by 1 to check if there are more rows .limit(READ_BATCH_SIZE + 1); @@ -46,6 +49,13 @@ const up = async (knex: Knex) => { const formattedRows = rows // exclude the last row since it was used to check if there are more rows .slice(0, READ_BATCH_SIZE) + .filter((row) => { + if (insertedIds.has(row.id)) { + return false; + } + insertedIds.add(row.id); + return true; + }) .map((row) => ({ id: row.id, row_id: row.row_id,