Browse Source

feat: attachment handling for duplicate model

nc-feat/attachment-clean-up
mertmit 4 months ago
parent
commit
f04949baa6
  1. 14
      packages/nocodb/src/db/BaseModelSqlv2.ts
  2. 6
      packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.processor.ts
  3. 8
      packages/nocodb/src/modules/jobs/jobs/export-import/import.service.ts

14
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -5288,6 +5288,14 @@ class BaseModelSqlv2 {
aiPkCol = this.model.primaryKeys.find((pk) => pk.ai); aiPkCol = this.model.primaryKeys.find((pk) => pk.ai);
agPkCol = this.model.primaryKeys.find((pk) => pk.meta?.ag); 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) { if ('beforeBulkInsert' in this) {
@ -5344,10 +5352,8 @@ class BaseModelSqlv2 {
} else { } else {
const returningObj: Record<string, string> = {}; const returningObj: Record<string, string> = {};
if (!raw) { for (const col of this.model.primaryKeys) {
for (const col of this.model.primaryKeys) { returningObj[col.title] = col.column_name;
returningObj[col.title] = col.column_name;
}
} }
responses = responses =

6
packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.processor.ts

@ -113,6 +113,7 @@ export class DuplicateProcessor {
destProject: dupProject, destProject: dupProject,
destBase: dupBase, destBase: dupBase,
hrTime, hrTime,
req,
}); });
} }
@ -241,6 +242,7 @@ export class DuplicateProcessor {
hrTime, hrTime,
modelFieldIds: fields, modelFieldIds: fields,
externalModels: relatedModels, externalModels: relatedModels,
req,
}); });
elapsedTime(hrTime, 'import model data', 'duplicateModel'); elapsedTime(hrTime, 'import model data', 'duplicateModel');
@ -381,6 +383,7 @@ export class DuplicateProcessor {
sourceModel, sourceModel,
...relatedModels.filter((m) => m.id !== sourceModel.id), ...relatedModels.filter((m) => m.id !== sourceModel.id),
], ],
req,
}); });
elapsedTime(hrTime, 'import model data', 'duplicateColumn'); elapsedTime(hrTime, 'import model data', 'duplicateColumn');
@ -420,6 +423,7 @@ export class DuplicateProcessor {
hrTime: { hrTime: [number, number] }; hrTime: { hrTime: [number, number] };
modelFieldIds?: Record<string, string[]>; modelFieldIds?: Record<string, string[]>;
externalModels?: Model[]; externalModels?: Model[];
req: any;
}, },
) { ) {
const { const {
@ -431,6 +435,7 @@ export class DuplicateProcessor {
hrTime, hrTime,
modelFieldIds, modelFieldIds,
externalModels, externalModels,
req,
} = param; } = param;
let handledLinks = []; let handledLinks = [];
@ -474,6 +479,7 @@ export class DuplicateProcessor {
destProject, destProject,
destBase, destBase,
destModel: model, destModel: model,
req,
}); });
handledLinks = await this.importService.importLinkFromCsvStream( handledLinks = await this.importService.importLinkFromCsvStream(

8
packages/nocodb/src/modules/jobs/jobs/export-import/import.service.ts

@ -1688,6 +1688,7 @@ export class ImportService {
destProject, destProject,
destBase, destBase,
destModel: model, destModel: model,
req,
}); });
elapsedTime( elapsedTime(
@ -1735,9 +1736,10 @@ export class ImportService {
destProject: Base; destProject: Base;
destBase: Source; destBase: Source;
destModel: Model; destModel: Model;
req: any;
}, },
): Promise<void> { ): Promise<void> {
const { idMap, dataStream, destBase, destProject, destModel } = param; const { idMap, dataStream, destBase, destProject, destModel, req } = param;
const headers: string[] = []; const headers: string[] = [];
let chunk = []; let chunk = [];
@ -1804,7 +1806,7 @@ export class ImportService {
baseName: destProject.id, baseName: destProject.id,
tableName: destModel.id, tableName: destModel.id,
body: chunk, body: chunk,
cookie: null, cookie: req,
chunkSize: chunk.length + 1, chunkSize: chunk.length + 1,
foreign_key_checks: !!destBase.isMeta(), foreign_key_checks: !!destBase.isMeta(),
raw: true, raw: true,
@ -1825,7 +1827,7 @@ export class ImportService {
baseName: destProject.id, baseName: destProject.id,
tableName: destModel.id, tableName: destModel.id,
body: chunk, body: chunk,
cookie: null, cookie: req,
chunkSize: chunk.length + 1, chunkSize: chunk.length + 1,
foreign_key_checks: !!destBase.isMeta(), foreign_key_checks: !!destBase.isMeta(),
raw: true, raw: true,

Loading…
Cancel
Save