|
|
@ -63,6 +63,10 @@ export class ImportService { |
|
|
|
const idMap = new Map<string, string>(); |
|
|
|
const idMap = new Map<string, string>(); |
|
|
|
const externalIdMap = new Map<string, string>(); |
|
|
|
const externalIdMap = new Map<string, string>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getIdOrExternalId = (k: string) => { |
|
|
|
|
|
|
|
return idMap.get(k) || externalIdMap.get(k); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const project = await Project.get(param.projectId); |
|
|
|
const project = await Project.get(param.projectId); |
|
|
|
|
|
|
|
|
|
|
|
if (!project) |
|
|
|
if (!project) |
|
|
@ -99,7 +103,10 @@ export class ImportService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (const col of model.columns) { |
|
|
|
for (const col of model.columns) { |
|
|
|
externalIdMap.set(`${idMap.get(model.id)}::${col.id}`, col.id); |
|
|
|
externalIdMap.set( |
|
|
|
|
|
|
|
`${model.project_id}::${model.base_id}::${model.id}::${col.id}`, |
|
|
|
|
|
|
|
col.id, |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -167,10 +174,10 @@ export class ImportService { |
|
|
|
column: withoutId({ |
|
|
|
column: withoutId({ |
|
|
|
...col, |
|
|
|
...col, |
|
|
|
...{ |
|
|
|
...{ |
|
|
|
parentId: idMap.get( |
|
|
|
parentId: getIdOrExternalId( |
|
|
|
getParentIdentifier(colOptions.fk_child_column_id), |
|
|
|
getParentIdentifier(colOptions.fk_child_column_id), |
|
|
|
), |
|
|
|
), |
|
|
|
childId: idMap.get( |
|
|
|
childId: getIdOrExternalId( |
|
|
|
getParentIdentifier(colOptions.fk_parent_column_id), |
|
|
|
getParentIdentifier(colOptions.fk_parent_column_id), |
|
|
|
), |
|
|
|
), |
|
|
|
type: colOptions.type, |
|
|
|
type: colOptions.type, |
|
|
@ -198,7 +205,7 @@ export class ImportService { |
|
|
|
modelData.id |
|
|
|
modelData.id |
|
|
|
? freshModelData |
|
|
|
? freshModelData |
|
|
|
: await Model.get( |
|
|
|
: await Model.get( |
|
|
|
idMap.get( |
|
|
|
getIdOrExternalId( |
|
|
|
getParentIdentifier(colOptions.fk_parent_column_id), |
|
|
|
getParentIdentifier(colOptions.fk_parent_column_id), |
|
|
|
), |
|
|
|
), |
|
|
|
); |
|
|
|
); |
|
|
@ -225,7 +232,7 @@ export class ImportService { |
|
|
|
if ( |
|
|
|
if ( |
|
|
|
nColumn?.colOptions?.fk_mm_model_id === |
|
|
|
nColumn?.colOptions?.fk_mm_model_id === |
|
|
|
linkMap.get(colOptions.fk_mm_model_id) && |
|
|
|
linkMap.get(colOptions.fk_mm_model_id) && |
|
|
|
nColumn.id !== idMap.get(col.id) |
|
|
|
nColumn.id !== getIdOrExternalId(col.id) |
|
|
|
) { |
|
|
|
) { |
|
|
|
idMap.set(childColumn.id, nColumn.id); |
|
|
|
idMap.set(childColumn.id, nColumn.id); |
|
|
|
|
|
|
|
|
|
|
@ -252,10 +259,10 @@ export class ImportService { |
|
|
|
column: withoutId({ |
|
|
|
column: withoutId({ |
|
|
|
...col, |
|
|
|
...col, |
|
|
|
...{ |
|
|
|
...{ |
|
|
|
parentId: idMap.get( |
|
|
|
parentId: getIdOrExternalId( |
|
|
|
getParentIdentifier(colOptions.fk_parent_column_id), |
|
|
|
getParentIdentifier(colOptions.fk_parent_column_id), |
|
|
|
), |
|
|
|
), |
|
|
|
childId: idMap.get( |
|
|
|
childId: getIdOrExternalId( |
|
|
|
getParentIdentifier(colOptions.fk_child_column_id), |
|
|
|
getParentIdentifier(colOptions.fk_child_column_id), |
|
|
|
), |
|
|
|
), |
|
|
|
type: colOptions.type, |
|
|
|
type: colOptions.type, |
|
|
@ -285,7 +292,9 @@ export class ImportService { |
|
|
|
const childModel = |
|
|
|
const childModel = |
|
|
|
colOptions.fk_related_model_id === modelData.id |
|
|
|
colOptions.fk_related_model_id === modelData.id |
|
|
|
? freshModelData |
|
|
|
? freshModelData |
|
|
|
: await Model.get(idMap.get(colOptions.fk_related_model_id)); |
|
|
|
: await Model.get( |
|
|
|
|
|
|
|
getIdOrExternalId(colOptions.fk_related_model_id), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (colOptions.fk_related_model_id !== modelData.id) |
|
|
|
if (colOptions.fk_related_model_id !== modelData.id) |
|
|
|
await childModel.getColumns(); |
|
|
|
await childModel.getColumns(); |
|
|
@ -303,11 +312,11 @@ export class ImportService { |
|
|
|
|
|
|
|
|
|
|
|
for (const nColumn of childModel.columns) { |
|
|
|
for (const nColumn of childModel.columns) { |
|
|
|
if ( |
|
|
|
if ( |
|
|
|
nColumn.id !== idMap.get(col.id) && |
|
|
|
nColumn.id !== getIdOrExternalId(col.id) && |
|
|
|
nColumn.colOptions?.fk_parent_column_id === |
|
|
|
nColumn.colOptions?.fk_parent_column_id === |
|
|
|
idMap.get(colOptions.fk_parent_column_id) && |
|
|
|
getIdOrExternalId(colOptions.fk_parent_column_id) && |
|
|
|
nColumn.colOptions?.fk_child_column_id === |
|
|
|
nColumn.colOptions?.fk_child_column_id === |
|
|
|
idMap.get(colOptions.fk_child_column_id) |
|
|
|
getIdOrExternalId(colOptions.fk_child_column_id) |
|
|
|
) { |
|
|
|
) { |
|
|
|
idMap.set(childColumn.id, nColumn.id); |
|
|
|
idMap.set(childColumn.id, nColumn.id); |
|
|
|
|
|
|
|
|
|
|
@ -336,18 +345,10 @@ export class ImportService { |
|
|
|
column: withoutId({ |
|
|
|
column: withoutId({ |
|
|
|
...col, |
|
|
|
...col, |
|
|
|
...{ |
|
|
|
...{ |
|
|
|
parentId: |
|
|
|
parentId: getIdOrExternalId( |
|
|
|
idMap.get( |
|
|
|
|
|
|
|
getParentIdentifier(colOptions.fk_child_column_id), |
|
|
|
|
|
|
|
) || |
|
|
|
|
|
|
|
externalIdMap.get( |
|
|
|
|
|
|
|
getParentIdentifier(colOptions.fk_child_column_id), |
|
|
|
getParentIdentifier(colOptions.fk_child_column_id), |
|
|
|
), |
|
|
|
), |
|
|
|
childId: |
|
|
|
childId: getIdOrExternalId( |
|
|
|
idMap.get( |
|
|
|
|
|
|
|
getParentIdentifier(colOptions.fk_parent_column_id), |
|
|
|
|
|
|
|
) || |
|
|
|
|
|
|
|
externalIdMap.get( |
|
|
|
|
|
|
|
getParentIdentifier(colOptions.fk_parent_column_id), |
|
|
|
getParentIdentifier(colOptions.fk_parent_column_id), |
|
|
|
), |
|
|
|
), |
|
|
|
type: colOptions.type, |
|
|
|
type: colOptions.type, |
|
|
@ -375,10 +376,7 @@ export class ImportService { |
|
|
|
modelData.id |
|
|
|
modelData.id |
|
|
|
? freshModelData |
|
|
|
? freshModelData |
|
|
|
: await Model.get( |
|
|
|
: await Model.get( |
|
|
|
idMap.get( |
|
|
|
getIdOrExternalId( |
|
|
|
getParentIdentifier(colOptions.fk_parent_column_id), |
|
|
|
|
|
|
|
) || |
|
|
|
|
|
|
|
externalIdMap.get( |
|
|
|
|
|
|
|
getParentIdentifier(colOptions.fk_parent_column_id), |
|
|
|
getParentIdentifier(colOptions.fk_parent_column_id), |
|
|
|
), |
|
|
|
), |
|
|
|
); |
|
|
|
); |
|
|
@ -416,8 +414,7 @@ export class ImportService { |
|
|
|
if ( |
|
|
|
if ( |
|
|
|
nColumn?.colOptions?.fk_mm_model_id === |
|
|
|
nColumn?.colOptions?.fk_mm_model_id === |
|
|
|
linkMap.get(colOptions.fk_mm_model_id) && |
|
|
|
linkMap.get(colOptions.fk_mm_model_id) && |
|
|
|
nColumn.id !== idMap.get(col.id) && |
|
|
|
nColumn.id !== getIdOrExternalId(col.id) |
|
|
|
nColumn.id !== externalIdMap.get(col.id) |
|
|
|
|
|
|
|
) { |
|
|
|
) { |
|
|
|
if (childColumn.id.includes('::')) { |
|
|
|
if (childColumn.id.includes('::')) { |
|
|
|
idMap.set(childColumn.id, nColumn.id); |
|
|
|
idMap.set(childColumn.id, nColumn.id); |
|
|
@ -463,18 +460,10 @@ export class ImportService { |
|
|
|
column: withoutId({ |
|
|
|
column: withoutId({ |
|
|
|
...col, |
|
|
|
...col, |
|
|
|
...{ |
|
|
|
...{ |
|
|
|
parentId: |
|
|
|
parentId: getIdOrExternalId( |
|
|
|
idMap.get( |
|
|
|
|
|
|
|
getParentIdentifier(colOptions.fk_parent_column_id), |
|
|
|
|
|
|
|
) || |
|
|
|
|
|
|
|
externalIdMap.get( |
|
|
|
|
|
|
|
getParentIdentifier(colOptions.fk_parent_column_id), |
|
|
|
getParentIdentifier(colOptions.fk_parent_column_id), |
|
|
|
), |
|
|
|
), |
|
|
|
childId: |
|
|
|
childId: getIdOrExternalId( |
|
|
|
idMap.get( |
|
|
|
|
|
|
|
getParentIdentifier(colOptions.fk_child_column_id), |
|
|
|
|
|
|
|
) || |
|
|
|
|
|
|
|
externalIdMap.get( |
|
|
|
|
|
|
|
getParentIdentifier(colOptions.fk_child_column_id), |
|
|
|
getParentIdentifier(colOptions.fk_child_column_id), |
|
|
|
), |
|
|
|
), |
|
|
|
type: colOptions.type, |
|
|
|
type: colOptions.type, |
|
|
@ -510,8 +499,7 @@ export class ImportService { |
|
|
|
colOptions.fk_related_model_id === modelData.id |
|
|
|
colOptions.fk_related_model_id === modelData.id |
|
|
|
? freshModelData |
|
|
|
? freshModelData |
|
|
|
: await Model.get( |
|
|
|
: await Model.get( |
|
|
|
idMap.get(colOptions.fk_related_model_id) || |
|
|
|
getIdOrExternalId(colOptions.fk_related_model_id), |
|
|
|
externalIdMap.get(colOptions.fk_related_model_id), |
|
|
|
|
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (colOptions.fk_related_model_id !== modelData.id) |
|
|
|
if (colOptions.fk_related_model_id !== modelData.id) |
|
|
@ -542,14 +530,11 @@ export class ImportService { |
|
|
|
|
|
|
|
|
|
|
|
for (const nColumn of childModel.columns) { |
|
|
|
for (const nColumn of childModel.columns) { |
|
|
|
if ( |
|
|
|
if ( |
|
|
|
nColumn.id !== idMap.get(col.id) && |
|
|
|
nColumn.id !== getIdOrExternalId(col.id) && |
|
|
|
nColumn.id !== externalIdMap.get(col.id) && |
|
|
|
nColumn.colOptions?.fk_parent_column_id === |
|
|
|
(nColumn.colOptions?.fk_parent_column_id === |
|
|
|
getIdOrExternalId(colOptions.fk_parent_column_id) && |
|
|
|
idMap.get(colOptions.fk_parent_column_id) || |
|
|
|
nColumn.colOptions?.fk_child_column_id === |
|
|
|
externalIdMap.get(colOptions.fk_parent_column_id)) && |
|
|
|
getIdOrExternalId(colOptions.fk_child_column_id) |
|
|
|
(nColumn.colOptions?.fk_child_column_id === |
|
|
|
|
|
|
|
idMap.get(colOptions.fk_child_column_id) || |
|
|
|
|
|
|
|
externalIdMap.get(colOptions.fk_child_column_id)) |
|
|
|
|
|
|
|
) { |
|
|
|
) { |
|
|
|
if (childColumn.id.includes('::')) { |
|
|
|
if (childColumn.id.includes('::')) { |
|
|
|
idMap.set(childColumn.id, nColumn.id); |
|
|
|
idMap.set(childColumn.id, nColumn.id); |
|
|
@ -595,18 +580,10 @@ export class ImportService { |
|
|
|
column: withoutId({ |
|
|
|
column: withoutId({ |
|
|
|
...col, |
|
|
|
...col, |
|
|
|
...{ |
|
|
|
...{ |
|
|
|
parentId: |
|
|
|
parentId: getIdOrExternalId( |
|
|
|
idMap.get( |
|
|
|
|
|
|
|
getParentIdentifier(colOptions.fk_parent_column_id), |
|
|
|
|
|
|
|
) || |
|
|
|
|
|
|
|
externalIdMap.get( |
|
|
|
|
|
|
|
getParentIdentifier(colOptions.fk_parent_column_id), |
|
|
|
getParentIdentifier(colOptions.fk_parent_column_id), |
|
|
|
), |
|
|
|
), |
|
|
|
childId: |
|
|
|
childId: getIdOrExternalId( |
|
|
|
idMap.get( |
|
|
|
|
|
|
|
getParentIdentifier(colOptions.fk_child_column_id), |
|
|
|
|
|
|
|
) || |
|
|
|
|
|
|
|
externalIdMap.get( |
|
|
|
|
|
|
|
getParentIdentifier(colOptions.fk_child_column_id), |
|
|
|
getParentIdentifier(colOptions.fk_child_column_id), |
|
|
|
), |
|
|
|
), |
|
|
|
type: colOptions.type, |
|
|
|
type: colOptions.type, |
|
|
@ -642,8 +619,7 @@ export class ImportService { |
|
|
|
colOptions.fk_related_model_id === modelData.id |
|
|
|
colOptions.fk_related_model_id === modelData.id |
|
|
|
? freshModelData |
|
|
|
? freshModelData |
|
|
|
: await Model.get( |
|
|
|
: await Model.get( |
|
|
|
idMap.get(colOptions.fk_related_model_id) || |
|
|
|
getIdOrExternalId(colOptions.fk_related_model_id), |
|
|
|
externalIdMap.get(colOptions.fk_related_model_id), |
|
|
|
|
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (colOptions.fk_related_model_id !== modelData.id) |
|
|
|
if (colOptions.fk_related_model_id !== modelData.id) |
|
|
@ -674,14 +650,11 @@ export class ImportService { |
|
|
|
|
|
|
|
|
|
|
|
for (const nColumn of childModel.columns) { |
|
|
|
for (const nColumn of childModel.columns) { |
|
|
|
if ( |
|
|
|
if ( |
|
|
|
nColumn.id !== idMap.get(col.id) && |
|
|
|
nColumn.id !== getIdOrExternalId(col.id) && |
|
|
|
nColumn.id !== externalIdMap.get(col.id) && |
|
|
|
nColumn.colOptions?.fk_parent_column_id === |
|
|
|
(nColumn.colOptions?.fk_parent_column_id === |
|
|
|
getIdOrExternalId(colOptions.fk_parent_column_id) && |
|
|
|
idMap.get(colOptions.fk_parent_column_id) || |
|
|
|
nColumn.colOptions?.fk_child_column_id === |
|
|
|
externalIdMap.get(colOptions.fk_parent_column_id)) && |
|
|
|
getIdOrExternalId(colOptions.fk_child_column_id) |
|
|
|
(nColumn.colOptions?.fk_child_column_id === |
|
|
|
|
|
|
|
idMap.get(colOptions.fk_child_column_id) || |
|
|
|
|
|
|
|
externalIdMap.get(colOptions.fk_child_column_id)) |
|
|
|
|
|
|
|
) { |
|
|
|
) { |
|
|
|
if (childColumn.id.includes('::')) { |
|
|
|
if (childColumn.id.includes('::')) { |
|
|
|
idMap.set(childColumn.id, nColumn.id); |
|
|
|
idMap.set(childColumn.id, nColumn.id); |
|
|
@ -772,14 +745,16 @@ export class ImportService { |
|
|
|
for (const col of sortedReferencedColumnSet) { |
|
|
|
for (const col of sortedReferencedColumnSet) { |
|
|
|
const { colOptions, ...flatCol } = col; |
|
|
|
const { colOptions, ...flatCol } = col; |
|
|
|
if (col.uidt === UITypes.Lookup) { |
|
|
|
if (col.uidt === UITypes.Lookup) { |
|
|
|
if (!idMap.get(colOptions.fk_relation_column_id)) continue; |
|
|
|
if (!getIdOrExternalId(colOptions.fk_relation_column_id)) continue; |
|
|
|
const freshModelData = await this.columnsService.columnAdd({ |
|
|
|
const freshModelData = await this.columnsService.columnAdd({ |
|
|
|
tableId: idMap.get(getParentIdentifier(col.id)), |
|
|
|
tableId: getIdOrExternalId(getParentIdentifier(col.id)), |
|
|
|
column: withoutId({ |
|
|
|
column: withoutId({ |
|
|
|
...flatCol, |
|
|
|
...flatCol, |
|
|
|
...{ |
|
|
|
...{ |
|
|
|
fk_lookup_column_id: idMap.get(colOptions.fk_lookup_column_id), |
|
|
|
fk_lookup_column_id: getIdOrExternalId( |
|
|
|
fk_relation_column_id: idMap.get( |
|
|
|
colOptions.fk_lookup_column_id, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
fk_relation_column_id: getIdOrExternalId( |
|
|
|
colOptions.fk_relation_column_id, |
|
|
|
colOptions.fk_relation_column_id, |
|
|
|
), |
|
|
|
), |
|
|
|
}, |
|
|
|
}, |
|
|
@ -794,14 +769,16 @@ export class ImportService { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (col.uidt === UITypes.Rollup) { |
|
|
|
} else if (col.uidt === UITypes.Rollup) { |
|
|
|
if (!idMap.get(colOptions.fk_relation_column_id)) continue; |
|
|
|
if (!getIdOrExternalId(colOptions.fk_relation_column_id)) continue; |
|
|
|
const freshModelData = await this.columnsService.columnAdd({ |
|
|
|
const freshModelData = await this.columnsService.columnAdd({ |
|
|
|
tableId: idMap.get(getParentIdentifier(col.id)), |
|
|
|
tableId: getIdOrExternalId(getParentIdentifier(col.id)), |
|
|
|
column: withoutId({ |
|
|
|
column: withoutId({ |
|
|
|
...flatCol, |
|
|
|
...flatCol, |
|
|
|
...{ |
|
|
|
...{ |
|
|
|
fk_rollup_column_id: idMap.get(colOptions.fk_rollup_column_id), |
|
|
|
fk_rollup_column_id: getIdOrExternalId( |
|
|
|
fk_relation_column_id: idMap.get( |
|
|
|
colOptions.fk_rollup_column_id, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
fk_relation_column_id: getIdOrExternalId( |
|
|
|
colOptions.fk_relation_column_id, |
|
|
|
colOptions.fk_relation_column_id, |
|
|
|
), |
|
|
|
), |
|
|
|
rollup_function: colOptions.rollup_function, |
|
|
|
rollup_function: colOptions.rollup_function, |
|
|
@ -818,7 +795,7 @@ export class ImportService { |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (col.uidt === UITypes.Formula) { |
|
|
|
} else if (col.uidt === UITypes.Formula) { |
|
|
|
const freshModelData = await this.columnsService.columnAdd({ |
|
|
|
const freshModelData = await this.columnsService.columnAdd({ |
|
|
|
tableId: idMap.get(getParentIdentifier(col.id)), |
|
|
|
tableId: getIdOrExternalId(getParentIdentifier(col.id)), |
|
|
|
column: withoutId({ |
|
|
|
column: withoutId({ |
|
|
|
...flatCol, |
|
|
|
...flatCol, |
|
|
|
...{ |
|
|
|
...{ |
|
|
@ -866,8 +843,8 @@ export class ImportService { |
|
|
|
viewId: vw.id, |
|
|
|
viewId: vw.id, |
|
|
|
filter: withoutId({ |
|
|
|
filter: withoutId({ |
|
|
|
...fl, |
|
|
|
...fl, |
|
|
|
fk_column_id: idMap.get(fl.fk_column_id), |
|
|
|
fk_column_id: getIdOrExternalId(fl.fk_column_id), |
|
|
|
fk_parent_id: idMap.get(fl.fk_parent_id), |
|
|
|
fk_parent_id: getIdOrExternalId(fl.fk_parent_id), |
|
|
|
}), |
|
|
|
}), |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -880,7 +857,7 @@ export class ImportService { |
|
|
|
viewId: vw.id, |
|
|
|
viewId: vw.id, |
|
|
|
sort: withoutId({ |
|
|
|
sort: withoutId({ |
|
|
|
...sr, |
|
|
|
...sr, |
|
|
|
fk_column_id: idMap.get(sr.fk_column_id), |
|
|
|
fk_column_id: getIdOrExternalId(sr.fk_column_id), |
|
|
|
}), |
|
|
|
}), |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -985,8 +962,8 @@ export class ImportService { |
|
|
|
hookId: hk.id, |
|
|
|
hookId: hk.id, |
|
|
|
filter: withoutId({ |
|
|
|
filter: withoutId({ |
|
|
|
...fl, |
|
|
|
...fl, |
|
|
|
fk_column_id: idMap.get(fl.fk_column_id), |
|
|
|
fk_column_id: getIdOrExternalId(fl.fk_column_id), |
|
|
|
fk_parent_id: idMap.get(fl.fk_parent_id), |
|
|
|
fk_parent_id: getIdOrExternalId(fl.fk_parent_id), |
|
|
|
}), |
|
|
|
}), |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|