From c52acce032aaa15543dc297aa01e9cab9fd2924a Mon Sep 17 00:00:00 2001 From: mertmit Date: Sat, 10 Aug 2024 07:31:58 +0000 Subject: [PATCH] fix: PR requested changes --- packages/nocodb/src/db/BaseModelSqlv2.ts | 23 ++++++++++++------ .../migration-jobs/init-migration-jobs.ts | 7 +++++- .../migration-jobs/nc_job_001_attachment.ts | 24 +++++++++---------- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index 6ed0061464..0f2d23a1c2 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -5293,9 +5293,7 @@ class BaseModelSqlv2 { await this.model.getColumns(this.context); await Promise.all( - insertDatas.map( - async (d) => await this.prepareNocoData(d, true, cookie), - ), + insertDatas.map((d) => this.prepareNocoData(d, true, cookie)), ); } @@ -6006,10 +6004,21 @@ class BaseModelSqlv2 { for (const c of attachmentColumns) { if (row[c.column_name]) { try { - const attachments = JSON.parse(row[c.column_name]); - for (const attachment of attachments) { - if (attachment.id) { - fileReferenceIds.push(attachment.id); + let attachments; + if (typeof row[c.column_name] === 'string') { + attachments = JSON.parse(row[c.column_name]); + for (const attachment of attachments) { + if (attachment.id) { + fileReferenceIds.push(attachment.id); + } + } + } + + if (Array.isArray(attachments)) { + for (const attachment of attachments) { + if (attachment.id) { + fileReferenceIds.push(attachment.id); + } } } } catch (e) { diff --git a/packages/nocodb/src/modules/jobs/migration-jobs/init-migration-jobs.ts b/packages/nocodb/src/modules/jobs/migration-jobs/init-migration-jobs.ts index 604f44fcaa..720c4d33b9 100644 --- a/packages/nocodb/src/modules/jobs/migration-jobs/init-migration-jobs.ts +++ b/packages/nocodb/src/modules/jobs/migration-jobs/init-migration-jobs.ts @@ -46,6 +46,11 @@ export class InitMigrationJobs { // check for lock if (migrationJobsState.locked) { + if (migrationJobsState.instance === instanceUuid) { + // lock taken by this instance + return; + } + // migration job is running, make sure it's not stalled by checking after 10 mins // stall check is updated every 5 mins setTimeout(() => { @@ -71,7 +76,7 @@ export class InitMigrationJobs { await updateMigrationJobsState(migrationJobsState, migrationJobsState); // wait for 2 seconds to confirm lock - await new Promise((resolve) => setTimeout(resolve, 2000)); + await new Promise((resolve) => setTimeout(resolve, 5000)); const confirmState = await getMigrationJobsState(); diff --git a/packages/nocodb/src/modules/jobs/migration-jobs/nc_job_001_attachment.ts b/packages/nocodb/src/modules/jobs/migration-jobs/nc_job_001_attachment.ts index 2b763e48dc..5ecfc31202 100644 --- a/packages/nocodb/src/modules/jobs/migration-jobs/nc_job_001_attachment.ts +++ b/packages/nocodb/src/modules/jobs/migration-jobs/nc_job_001_attachment.ts @@ -140,19 +140,19 @@ export class AttachmentMigrationProcessor { } }); - await new Promise((resolve, reject) => { - fileScanStream.on('end', resolve); - fileScanStream.on('error', reject); - }) - .then(() => { - filesCount += fileReferenceBuffer.length; - this.log(`Completed scanning with ${filesCount} files`); - }) - .catch((e) => { - this.log(`There was an error while scanning files`); - this.log(e); - err = e; + try { + await new Promise((resolve, reject) => { + fileScanStream.on('end', resolve); + fileScanStream.on('error', reject); }); + } catch (e) { + this.log(`There was an error while scanning files`); + this.log(e); + throw e; + } + + filesCount += fileReferenceBuffer.length; + this.log(`Completed scanning with ${filesCount} files`); if (err) { throw err;