From f04949baa6edae556e2b639c5307c021e3af32c8 Mon Sep 17 00:00:00 2001 From: mertmit Date: Sat, 10 Aug 2024 07:31:54 +0000 Subject: [PATCH] feat: attachment handling for duplicate model --- packages/nocodb/src/db/BaseModelSqlv2.ts | 14 ++++++++++---- .../jobs/jobs/export-import/duplicate.processor.ts | 6 ++++++ .../jobs/jobs/export-import/import.service.ts | 8 +++++--- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index dee6a293fe..dea8671182 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -5288,6 +5288,14 @@ class BaseModelSqlv2 { aiPkCol = this.model.primaryKeys.find((pk) => pk.ai); agPkCol = this.model.primaryKeys.find((pk) => pk.meta?.ag); + } else { + await this.model.getColumns(this.context); + + await Promise.all( + insertDatas.map( + async (d) => await this.prepareNocoData(d, true, cookie), + ), + ); } if ('beforeBulkInsert' in this) { @@ -5344,10 +5352,8 @@ class BaseModelSqlv2 { } else { const returningObj: Record = {}; - if (!raw) { - for (const col of this.model.primaryKeys) { - returningObj[col.title] = col.column_name; - } + for (const col of this.model.primaryKeys) { + returningObj[col.title] = col.column_name; } responses = diff --git a/packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.processor.ts b/packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.processor.ts index be8c647033..0447ef2a97 100644 --- a/packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.processor.ts +++ b/packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.processor.ts @@ -113,6 +113,7 @@ export class DuplicateProcessor { destProject: dupProject, destBase: dupBase, hrTime, + req, }); } @@ -241,6 +242,7 @@ export class DuplicateProcessor { hrTime, modelFieldIds: fields, externalModels: relatedModels, + req, }); elapsedTime(hrTime, 'import model data', 'duplicateModel'); @@ -381,6 +383,7 @@ export class DuplicateProcessor { sourceModel, ...relatedModels.filter((m) => m.id !== sourceModel.id), ], + req, }); elapsedTime(hrTime, 'import model data', 'duplicateColumn'); @@ -420,6 +423,7 @@ export class DuplicateProcessor { hrTime: { hrTime: [number, number] }; modelFieldIds?: Record; externalModels?: Model[]; + req: any; }, ) { const { @@ -431,6 +435,7 @@ export class DuplicateProcessor { hrTime, modelFieldIds, externalModels, + req, } = param; let handledLinks = []; @@ -474,6 +479,7 @@ export class DuplicateProcessor { destProject, destBase, destModel: model, + req, }); handledLinks = await this.importService.importLinkFromCsvStream( diff --git a/packages/nocodb/src/modules/jobs/jobs/export-import/import.service.ts b/packages/nocodb/src/modules/jobs/jobs/export-import/import.service.ts index 90a7e2888c..8d78fff5da 100644 --- a/packages/nocodb/src/modules/jobs/jobs/export-import/import.service.ts +++ b/packages/nocodb/src/modules/jobs/jobs/export-import/import.service.ts @@ -1688,6 +1688,7 @@ export class ImportService { destProject, destBase, destModel: model, + req, }); elapsedTime( @@ -1735,9 +1736,10 @@ export class ImportService { destProject: Base; destBase: Source; destModel: Model; + req: any; }, ): Promise { - const { idMap, dataStream, destBase, destProject, destModel } = param; + const { idMap, dataStream, destBase, destProject, destModel, req } = param; const headers: string[] = []; let chunk = []; @@ -1804,7 +1806,7 @@ export class ImportService { baseName: destProject.id, tableName: destModel.id, body: chunk, - cookie: null, + cookie: req, chunkSize: chunk.length + 1, foreign_key_checks: !!destBase.isMeta(), raw: true, @@ -1825,7 +1827,7 @@ export class ImportService { baseName: destProject.id, tableName: destModel.id, body: chunk, - cookie: null, + cookie: req, chunkSize: chunk.length + 1, foreign_key_checks: !!destBase.isMeta(), raw: true,