Browse Source

fix: add order by to comment migration (#8598)

* fix: add order by to comment migration

* fix: handle corner case for migration
pull/8601/head
Mert E 1 month ago committed by GitHub
parent
commit
7ca13e862d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 10
      packages/nocodb/src/meta/migrations/v2/nc_047_comment_migration.ts

10
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<string>();
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,

Loading…
Cancel
Save