From ad4b5f671cf6a5f56096d36027b266999757f6c9 Mon Sep 17 00:00:00 2001 From: mertmit Date: Sat, 10 Aug 2024 07:32:01 +0000 Subject: [PATCH] fix: better scan and confirm existing ids --- packages/nocodb/src/models/FileReference.ts | 1 + .../migration-jobs/nc_job_001_attachment.ts | 27 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/nocodb/src/models/FileReference.ts b/packages/nocodb/src/models/FileReference.ts index e76ed4b245..dd755c836f 100644 --- a/packages/nocodb/src/models/FileReference.ts +++ b/packages/nocodb/src/models/FileReference.ts @@ -29,6 +29,7 @@ export default class FileReference { ncMeta = Noco.ncMeta, ) { const insertObj = extractProps(fileRefObj, [ + 'id', 'storage', 'file_url', 'file_size', 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 e355020576..03a20353e1 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 @@ -86,8 +86,13 @@ export class AttachmentMigration { fileReferenceBuffer.push({ file_path: file }); if (fileReferenceBuffer.length >= 100) { + fileScanStream.pause(); + try { - const processBuffer = fileReferenceBuffer.splice(0); + const processBuffer = fileReferenceBuffer.splice( + 0, + fileReferenceBuffer.length, + ); filesCount += processBuffer.length; @@ -124,6 +129,8 @@ export class AttachmentMigration { this.log(e); err = e; } + + fileScanStream.resume(); } }); @@ -370,6 +377,24 @@ export class AttachmentMigration { }); updateRequired = true; + } else { + const fileReference = await FileReference.get( + context, + attachment.id, + ); + + if (!fileReference) { + await FileReference.insert(context, { + id: attachment.id, + source_id: source.id, + fk_model_id, + fk_column_id: column.id, + file_url: attachment.path || attachment.url, + file_size: attachment.size, + is_external: !source.isMeta(), + deleted: false, + }); + } } } } catch (e) {