Browse Source

refactor: on at import create instead of LTAR create Links

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5848/head
Pranav C 1 year ago
parent
commit
cfc4d46251
  1. 18
      packages/nocodb/src/modules/jobs/jobs/at-import/at-import.processor.ts

18
packages/nocodb/src/modules/jobs/jobs/at-import/at-import.processor.ts

@ -9,6 +9,7 @@ import utc from 'dayjs/plugin/utc';
import tinycolor from 'tinycolor2'; import tinycolor from 'tinycolor2';
import { Process, Processor } from '@nestjs/bull'; import { Process, Processor } from '@nestjs/bull';
import { Job } from 'bull'; import { Job } from 'bull';
import { isLinksOrLTAR } from '../../../../../../nocodb-sdk/src'
import extractRolesObj from '../../../../utils/extractRolesObj'; import extractRolesObj from '../../../../utils/extractRolesObj';
import { AttachmentsService } from '../../../../services/attachments.service'; import { AttachmentsService } from '../../../../services/attachments.service';
import { ColumnsService } from '../../../../services/columns.service'; import { ColumnsService } from '../../../../services/columns.service';
@ -270,7 +271,7 @@ export class AtImportProcessor {
// base mapping table // base mapping table
const aTblNcTypeMap = { const aTblNcTypeMap = {
foreignKey: UITypes.LinkToAnotherRecord, foreignKey: UITypes.Links,
text: UITypes.SingleLineText, text: UITypes.SingleLineText,
multilineText: UITypes.LongText, multilineText: UITypes.LongText,
richText: UITypes.LongText, richText: UITypes.LongText,
@ -785,7 +786,7 @@ export class AtImportProcessor {
const ncTbl: any = await this.columnsService.columnAdd({ const ncTbl: any = await this.columnsService.columnAdd({
tableId: srcTableId, tableId: srcTableId,
column: { column: {
uidt: UITypes.LinkToAnotherRecord, uidt: UITypes.Links,
title: ncName.title, title: ncName.title,
column_name: ncName.column_name, column_name: ncName.column_name,
parentId: srcTableId, parentId: srcTableId,
@ -867,14 +868,14 @@ export class AtImportProcessor {
updateMigrationSkipLog( updateMigrationSkipLog(
parentTblSchema?.title, parentTblSchema?.title,
ncLinkMappingTable[x].nc.title, ncLinkMappingTable[x].nc.title,
UITypes.LinkToAnotherRecord, UITypes.Links,
'Link error', 'Link error',
); );
continue; continue;
} }
// hack // fix me // hack // fix me
if (parentLinkColumn.uidt !== 'LinkToAnotherRecord') { if (!isLinksOrLTAR(parentLinkColumn)) {
parentLinkColumn = parentTblSchema.columns.find( parentLinkColumn = parentTblSchema.columns.find(
(col) => col.title === ncLinkMappingTable[x].nc.title + '_2', (col) => col.title === ncLinkMappingTable[x].nc.title + '_2',
); );
@ -888,7 +889,7 @@ export class AtImportProcessor {
// //
childLinkColumn = childTblSchema.columns.find( childLinkColumn = childTblSchema.columns.find(
(col) => (col) =>
col.uidt === UITypes.LinkToAnotherRecord && isLinksOrLTAR(col) &&
col.colOptions.fk_child_column_id === col.colOptions.fk_child_column_id ===
parentLinkColumn.colOptions.fk_child_column_id && parentLinkColumn.colOptions.fk_child_column_id &&
col.colOptions.fk_parent_column_id === col.colOptions.fk_parent_column_id ===
@ -900,7 +901,7 @@ export class AtImportProcessor {
// //
childLinkColumn = childTblSchema.columns.find( childLinkColumn = childTblSchema.columns.find(
(col) => (col) =>
col.uidt === UITypes.LinkToAnotherRecord && isLinksOrLTAR(col) &&
col.colOptions.fk_child_column_id === col.colOptions.fk_child_column_id ===
parentLinkColumn.colOptions.fk_parent_column_id && parentLinkColumn.colOptions.fk_parent_column_id &&
col.colOptions.fk_parent_column_id === col.colOptions.fk_parent_column_id ===
@ -1431,7 +1432,7 @@ export class AtImportProcessor {
// always process LTAR, Lookup, and Rollup columns as we delete the key after processing // always process LTAR, Lookup, and Rollup columns as we delete the key after processing
if ( if (
!value && !value &&
dt !== UITypes.LinkToAnotherRecord && !isLinksOrLTAR(dt) &&
dt !== UITypes.Lookup && dt !== UITypes.Lookup &&
dt !== UITypes.Rollup dt !== UITypes.Rollup
) { ) {
@ -1450,6 +1451,7 @@ export class AtImportProcessor {
// we will pick up LTAR once all table data's are in place // we will pick up LTAR once all table data's are in place
case UITypes.LinkToAnotherRecord: case UITypes.LinkToAnotherRecord:
case UITypes.Links:
if (storeLinks) { if (storeLinks) {
if (ncLinkDataStore[table.title][record.id] === undefined) if (ncLinkDataStore[table.title][record.id] === undefined)
ncLinkDataStore[table.title][record.id] = { ncLinkDataStore[table.title][record.id] = {
@ -1971,7 +1973,7 @@ export class AtImportProcessor {
const ncTbl = await nc_getTableSchema(aTblSchema[idx].name); const ncTbl = await nc_getTableSchema(aTblSchema[idx].name);
const linkColumn = ncTbl.columns.filter( const linkColumn = ncTbl.columns.filter(
(x) => x.uidt === UITypes.LinkToAnotherRecord, (x) => isLinksOrLTAR(x)
); );
const lookup = ncTbl.columns.filter((x) => x.uidt === UITypes.Lookup); const lookup = ncTbl.columns.filter((x) => x.uidt === UITypes.Lookup);
const rollup = ncTbl.columns.filter((x) => x.uidt === UITypes.Rollup); const rollup = ncTbl.columns.filter((x) => x.uidt === UITypes.Rollup);

Loading…
Cancel
Save