Browse Source

fix: self link duplicate issues (#8535)

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/8540/head
Mert E 6 months ago committed by GitHub
parent
commit
c261bdc36f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 13
      packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.processor.ts
  2. 64
      packages/nocodb/src/modules/jobs/jobs/export-import/import.service.ts

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

@ -205,12 +205,12 @@ export class DuplicateProcessor {
(c.colOptions.type === RelationTypes.BELONGS_TO ||
(c.colOptions.type === RelationTypes.ONE_TO_ONE &&
c.meta?.bt)) &&
c.colOptions.fk_related_model_id === modelId,
c.colOptions.fk_related_model_id === sourceModel.id,
)
.map((c) => c.id);
if (bts.length > 0) {
fields[md.id] = [md.primaryKey.id];
fields[md.id] = fields[md.id] ? fields[md.id] : [md.primaryKey.id];
fields[md.id].push(...bts);
}
}
@ -294,14 +294,6 @@ export class DuplicateProcessor {
throw new Error(`Export failed for model '${sourceModel.id}'`);
}
exportedModel.model.columns = exportedModel.model.columns.filter((c) =>
c.id.includes(columnId),
);
if (exportedModel.model.columns.length !== 1) {
throw new Error(`There was an error duplicating column!`);
}
const replacedColumn = exportedModel.model.columns.find((c) =>
c.id.includes(columnId),
);
@ -325,6 +317,7 @@ export class DuplicateProcessor {
req,
externalModels: relatedModels,
existingModel: sourceModel,
importColumnIds: [columnId],
});
elapsedTime(hrTime, 'import model schema', 'duplicateColumn');

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

@ -81,6 +81,7 @@ export class ImportService {
req: NcRequest;
externalModels?: Model[];
existingModel?: Model;
importColumnIds?: string[];
}) {
const hrTime = initTime();
@ -143,7 +144,12 @@ export class ImportService {
const modelData = data.model;
const reducedColumnSet = modelData.columns.filter(
(a) => !isVirtualCol(a) && a.uidt !== UITypes.ForeignKey,
(a) =>
!isVirtualCol(a) &&
a.uidt !== UITypes.ForeignKey &&
(param.importColumnIds
? param.importColumnIds.includes(getEntityIdentifier(a.id))
: true),
);
// create table with static columns
@ -228,7 +234,14 @@ export class ImportService {
const modelData = data.model;
const table = tableReferences.get(modelData.id);
const linkedColumnSet = modelData.columns.filter((a) => isLinksOrLTAR(a));
const linkedColumnSet = modelData.columns.filter(
(a) =>
isLinksOrLTAR(a) &&
!a.system &&
(param.importColumnIds
? param.importColumnIds.includes(getEntityIdentifier(a.id))
: true),
);
for (const col of linkedColumnSet) {
if (col.colOptions) {
@ -299,9 +312,8 @@ export class ImportService {
colOptions.fk_mm_model_id && a.id !== col.id,
);
// referencing the same model
if (colOptions.fk_related_model_id === modelData.id) {
continue;
childColumn.title = `${childColumn.title} copy`;
}
for (const nColumn of childModel.columns) {
@ -391,31 +403,8 @@ export class ImportService {
a.id !== col.id,
);
// referencing the same model
if (colOptions.fk_related_model_id === modelData.id) {
const counterRelationType =
colOptions.type === 'hm' ? 'bt' : 'oo';
const oldCol = childModel.columns.find(
(oColumn) =>
oColumn.colOptions?.fk_parent_column_id ===
getEntityIdentifier(colOptions.fk_parent_column_id) &&
oColumn.colOptions?.fk_child_column_id ===
getEntityIdentifier(colOptions.fk_child_column_id) &&
oColumn.colOptions?.type === counterRelationType,
);
const col = childModel.columns.find(
(nColumn) =>
nColumn.colOptions?.fk_parent_column_id ===
getIdOrExternalId(colOptions.fk_parent_column_id) &&
nColumn.colOptions?.fk_child_column_id ===
getIdOrExternalId(colOptions.fk_child_column_id) &&
nColumn.colOptions?.type === counterRelationType,
);
idMap.set(
`${oldCol.base_id}::${oldCol.source_id}::${oldCol.fk_model_id}::${oldCol.id}`,
col.id,
);
continue;
childColumn.title = `${childColumn.title} copy`;
}
for (const nColumn of childModel.columns) {
@ -520,6 +509,10 @@ export class ImportService {
a.id !== getEntityIdentifier(col.id)),
);
if (colOptions.fk_related_model_id === modelData.id) {
childColumn.title = `${childColumn.title} copy`;
}
for (const nColumn of childModel.columns) {
if (
nColumn?.colOptions?.fk_mm_model_id ===
@ -643,6 +636,10 @@ export class ImportService {
a.id !== getEntityIdentifier(col.id)),
);
if (colOptions.fk_related_model_id === modelData.id) {
childColumn.title = `${childColumn.title} copy`;
}
for (const nColumn of childModel.columns) {
if (
nColumn.id !== getIdOrExternalId(col.id) &&
@ -768,6 +765,10 @@ export class ImportService {
a.id !== getEntityIdentifier(col.id)),
);
if (colOptions.fk_related_model_id === modelData.id) {
childColumn.title = `${childColumn.title} copy`;
}
for (const nColumn of childModel.columns) {
if (
nColumn.id !== getIdOrExternalId(col.id) &&
@ -815,7 +816,7 @@ export class ImportService {
referencedColumnSet.push(
...modelData.columns.filter(
(a) =>
a.uidt === UITypes.Lookup ||
(a.uidt === UITypes.Lookup ||
a.uidt === UITypes.Rollup ||
a.uidt === UITypes.Formula ||
a.uidt === UITypes.QrCode ||
@ -823,7 +824,10 @@ export class ImportService {
a.uidt === UITypes.LastModifiedTime ||
a.uidt === UITypes.CreatedBy ||
a.uidt === UITypes.LastModifiedBy ||
a.uidt === UITypes.Barcode,
a.uidt === UITypes.Barcode) &&
(param.importColumnIds
? param.importColumnIds.includes(getEntityIdentifier(a.id))
: true),
),
);
}

Loading…
Cancel
Save