|
|
@ -49,7 +49,7 @@ export class DuplicateProcessor { |
|
|
|
const source = await Source.get(context, sourceId); |
|
|
|
const source = await Source.get(context, sourceId); |
|
|
|
|
|
|
|
|
|
|
|
const targetContext = { |
|
|
|
const targetContext = { |
|
|
|
...context, |
|
|
|
workspace_id: dupProject.fk_workspace_id, |
|
|
|
base_id: dupProject.id, |
|
|
|
base_id: dupProject.id, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -101,7 +101,7 @@ export class DuplicateProcessor { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!excludeData) { |
|
|
|
if (!excludeData) { |
|
|
|
await this.importModelsData(targetContext, { |
|
|
|
await this.importModelsData(targetContext, context, { |
|
|
|
idMap, |
|
|
|
idMap, |
|
|
|
sourceProject: base, |
|
|
|
sourceProject: base, |
|
|
|
sourceModels: models, |
|
|
|
sourceModels: models, |
|
|
@ -225,7 +225,7 @@ export class DuplicateProcessor { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await this.importModelsData(context, { |
|
|
|
await this.importModelsData(context, context, { |
|
|
|
idMap, |
|
|
|
idMap, |
|
|
|
sourceProject: base, |
|
|
|
sourceProject: base, |
|
|
|
sourceModels: [sourceModel], |
|
|
|
sourceModels: [sourceModel], |
|
|
@ -362,7 +362,7 @@ export class DuplicateProcessor { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await this.importModelsData(context, { |
|
|
|
await this.importModelsData(context, context, { |
|
|
|
idMap, |
|
|
|
idMap, |
|
|
|
sourceProject: base, |
|
|
|
sourceProject: base, |
|
|
|
sourceModels: [], |
|
|
|
sourceModels: [], |
|
|
@ -405,7 +405,8 @@ export class DuplicateProcessor { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async importModelsData( |
|
|
|
async importModelsData( |
|
|
|
context: NcContext, |
|
|
|
targetContext: NcContext, |
|
|
|
|
|
|
|
sourceContext: NcContext, |
|
|
|
param: { |
|
|
|
param: { |
|
|
|
idMap: Map<string, string>; |
|
|
|
idMap: Map<string, string>; |
|
|
|
sourceProject: Base; |
|
|
|
sourceProject: Base; |
|
|
@ -444,7 +445,7 @@ export class DuplicateProcessor { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
this.exportService |
|
|
|
this.exportService |
|
|
|
.streamModelDataAsCsv(context, { |
|
|
|
.streamModelDataAsCsv(sourceContext, { |
|
|
|
dataStream, |
|
|
|
dataStream, |
|
|
|
linkStream, |
|
|
|
linkStream, |
|
|
|
baseId: sourceProject.id, |
|
|
|
baseId: sourceProject.id, |
|
|
@ -459,11 +460,11 @@ export class DuplicateProcessor { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const model = await Model.get( |
|
|
|
const model = await Model.get( |
|
|
|
context, |
|
|
|
targetContext, |
|
|
|
findWithIdentifier(idMap, sourceModel.id), |
|
|
|
findWithIdentifier(idMap, sourceModel.id), |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await this.importService.importDataFromCsvStream(context, { |
|
|
|
await this.importService.importDataFromCsvStream(targetContext, { |
|
|
|
idMap, |
|
|
|
idMap, |
|
|
|
dataStream, |
|
|
|
dataStream, |
|
|
|
destProject, |
|
|
|
destProject, |
|
|
@ -471,13 +472,16 @@ export class DuplicateProcessor { |
|
|
|
destModel: model, |
|
|
|
destModel: model, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
handledLinks = await this.importService.importLinkFromCsvStream(context, { |
|
|
|
handledLinks = await this.importService.importLinkFromCsvStream( |
|
|
|
idMap, |
|
|
|
targetContext, |
|
|
|
linkStream, |
|
|
|
{ |
|
|
|
destProject, |
|
|
|
idMap, |
|
|
|
destBase, |
|
|
|
linkStream, |
|
|
|
handledLinks, |
|
|
|
destProject, |
|
|
|
}); |
|
|
|
destBase, |
|
|
|
|
|
|
|
handledLinks, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
elapsedTime( |
|
|
|
elapsedTime( |
|
|
|
hrTime, |
|
|
|
hrTime, |
|
|
@ -506,7 +510,7 @@ export class DuplicateProcessor { |
|
|
|
let error = null; |
|
|
|
let error = null; |
|
|
|
|
|
|
|
|
|
|
|
this.exportService |
|
|
|
this.exportService |
|
|
|
.streamModelDataAsCsv(context, { |
|
|
|
.streamModelDataAsCsv(targetContext, { |
|
|
|
dataStream, |
|
|
|
dataStream, |
|
|
|
linkStream, |
|
|
|
linkStream, |
|
|
|
baseId: sourceProject.id, |
|
|
|
baseId: sourceProject.id, |
|
|
@ -524,7 +528,7 @@ export class DuplicateProcessor { |
|
|
|
const headers: string[] = []; |
|
|
|
const headers: string[] = []; |
|
|
|
let chunk = []; |
|
|
|
let chunk = []; |
|
|
|
|
|
|
|
|
|
|
|
const model = await Model.get(context, sourceModel.id); |
|
|
|
const model = await Model.get(targetContext, sourceModel.id); |
|
|
|
|
|
|
|
|
|
|
|
await new Promise((resolve) => { |
|
|
|
await new Promise((resolve) => { |
|
|
|
papaparse.parse(dataStream, { |
|
|
|
papaparse.parse(dataStream, { |
|
|
@ -535,7 +539,7 @@ export class DuplicateProcessor { |
|
|
|
for (const header of results.data as any) { |
|
|
|
for (const header of results.data as any) { |
|
|
|
const id = idMap.get(header); |
|
|
|
const id = idMap.get(header); |
|
|
|
if (id) { |
|
|
|
if (id) { |
|
|
|
const col = await Column.get(context, { |
|
|
|
const col = await Column.get(targetContext, { |
|
|
|
source_id: destBase.id, |
|
|
|
source_id: destBase.id, |
|
|
|
colId: id, |
|
|
|
colId: id, |
|
|
|
}); |
|
|
|
}); |
|
|
@ -545,7 +549,7 @@ export class DuplicateProcessor { |
|
|
|
(col.colOptions?.type === RelationTypes.ONE_TO_ONE && |
|
|
|
(col.colOptions?.type === RelationTypes.ONE_TO_ONE && |
|
|
|
col.meta?.bt) |
|
|
|
col.meta?.bt) |
|
|
|
) { |
|
|
|
) { |
|
|
|
const childCol = await Column.get(context, { |
|
|
|
const childCol = await Column.get(targetContext, { |
|
|
|
source_id: destBase.id, |
|
|
|
source_id: destBase.id, |
|
|
|
colId: col.colOptions.fk_child_column_id, |
|
|
|
colId: col.colOptions.fk_child_column_id, |
|
|
|
}); |
|
|
|
}); |
|
|
@ -585,13 +589,16 @@ export class DuplicateProcessor { |
|
|
|
// remove empty rows (only pk is present)
|
|
|
|
// remove empty rows (only pk is present)
|
|
|
|
chunk = chunk.filter((r) => Object.keys(r).length > 1); |
|
|
|
chunk = chunk.filter((r) => Object.keys(r).length > 1); |
|
|
|
if (chunk.length > 0) { |
|
|
|
if (chunk.length > 0) { |
|
|
|
await this.bulkDataService.bulkDataUpdate(context, { |
|
|
|
await this.bulkDataService.bulkDataUpdate( |
|
|
|
baseName: destProject.id, |
|
|
|
targetContext, |
|
|
|
tableName: model.id, |
|
|
|
{ |
|
|
|
body: chunk, |
|
|
|
baseName: destProject.id, |
|
|
|
cookie: null, |
|
|
|
tableName: model.id, |
|
|
|
raw: true, |
|
|
|
body: chunk, |
|
|
|
}); |
|
|
|
cookie: null, |
|
|
|
|
|
|
|
raw: true, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
this.debugLog(e); |
|
|
|
this.debugLog(e); |
|
|
@ -608,7 +615,7 @@ export class DuplicateProcessor { |
|
|
|
// remove empty rows (only pk is present)
|
|
|
|
// remove empty rows (only pk is present)
|
|
|
|
chunk = chunk.filter((r) => Object.keys(r).length > 1); |
|
|
|
chunk = chunk.filter((r) => Object.keys(r).length > 1); |
|
|
|
if (chunk.length > 0) { |
|
|
|
if (chunk.length > 0) { |
|
|
|
await this.bulkDataService.bulkDataUpdate(context, { |
|
|
|
await this.bulkDataService.bulkDataUpdate(targetContext, { |
|
|
|
baseName: destProject.id, |
|
|
|
baseName: destProject.id, |
|
|
|
tableName: model.id, |
|
|
|
tableName: model.id, |
|
|
|
body: chunk, |
|
|
|
body: chunk, |
|
|
@ -629,7 +636,7 @@ export class DuplicateProcessor { |
|
|
|
if (error) throw error; |
|
|
|
if (error) throw error; |
|
|
|
|
|
|
|
|
|
|
|
handledLinks = await this.importService.importLinkFromCsvStream( |
|
|
|
handledLinks = await this.importService.importLinkFromCsvStream( |
|
|
|
context, |
|
|
|
targetContext, |
|
|
|
{ |
|
|
|
{ |
|
|
|
idMap, |
|
|
|
idMap, |
|
|
|
linkStream, |
|
|
|
linkStream, |
|
|
|