Browse Source

fix: disable fk checks for external bases

nc-fix/at-attachments
mertmit 10 months ago
parent
commit
eb2e791243
  1. 8
      packages/nocodb/src/modules/jobs/jobs/at-import/at-import.processor.ts
  2. 36
      packages/nocodb/src/modules/jobs/jobs/at-import/helpers/readAndProcessData.ts

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

@ -14,7 +14,7 @@ import FetchAT from './helpers/fetchAT';
import { importData, importLTARData } from './helpers/readAndProcessData'; import { importData, importLTARData } from './helpers/readAndProcessData';
import EntityMap from './helpers/EntityMap'; import EntityMap from './helpers/EntityMap';
import type { UserType } from 'nocodb-sdk'; import type { UserType } from 'nocodb-sdk';
import type { Base } from '~/models'; import { type Base, Source } from '~/models';
import { sanitizeColumnName } from '~/helpers'; import { sanitizeColumnName } from '~/helpers';
import { AttachmentsService } from '~/services/attachments.service'; import { AttachmentsService } from '~/services/attachments.service';
import { ColumnsService } from '~/services/columns.service'; import { ColumnsService } from '~/services/columns.service';
@ -2457,6 +2457,9 @@ export class AtImportProcessor {
sourceId: syncDB.sourceId, sourceId: syncDB.sourceId,
roles: { ...userRole, owner: true }, roles: { ...userRole, owner: true },
}); });
const source = await Source.get(syncDB.sourceId);
recordPerfStats(_perfStart, 'base.tableList'); recordPerfStats(_perfStart, 'base.tableList');
logBasic('Reading Records...'); logBasic('Reading Records...');
@ -2484,7 +2487,8 @@ export class AtImportProcessor {
table: ncTbl, table: ncTbl,
atBase, atBase,
nocoBaseDataProcessing_v2, nocoBaseDataProcessing_v2,
sDB: syncDB, syncDB,
source,
services: { services: {
tableService: this.tablesService, tableService: this.tablesService,
bulkDataService: this.bulkDataAliasService, bulkDataService: this.bulkDataAliasService,

36
packages/nocodb/src/modules/jobs/jobs/at-import/helpers/readAndProcessData.ts

@ -2,12 +2,11 @@
import { isLinksOrLTAR, RelationTypes } from 'nocodb-sdk'; import { isLinksOrLTAR, RelationTypes } from 'nocodb-sdk';
import sizeof from 'object-sizeof'; import sizeof from 'object-sizeof';
import { Logger } from '@nestjs/common'; import { Logger } from '@nestjs/common';
import EntityMap from './EntityMap'; import type { BulkDataAliasService } from '~/services/bulk-data-alias.service';
import type { BulkDataAliasService } from '../../../../../services/bulk-data-alias.service'; import type { TablesService } from '~/services/tables.service';
import type { TablesService } from '../../../../../services/tables.service';
// @ts-ignore
import type { AirtableBase } from 'airtable/lib/airtable_base'; import type { AirtableBase } from 'airtable/lib/airtable_base';
import type { TableType } from 'nocodb-sdk'; import type { TableType } from 'nocodb-sdk';
import type { Source } from '~/models';
const logger = new Logger('BaseModelSqlv2'); const logger = new Logger('BaseModelSqlv2');
@ -108,7 +107,8 @@ export async function importData({
table, table,
atBase, atBase,
nocoBaseDataProcessing_v2, nocoBaseDataProcessing_v2,
sDB, syncDB,
source,
logBasic = (_str) => {}, logBasic = (_str) => {},
logDetailed = (_str) => {}, logDetailed = (_str) => {},
logWarning = (_str) => {}, logWarning = (_str) => {},
@ -118,6 +118,7 @@ export async function importData({
table: { title?: string; id?: string }; table: { title?: string; id?: string };
fields?; fields?;
atBase: AirtableBase; atBase: AirtableBase;
source: Source;
logBasic: (string) => void; logBasic: (string) => void;
logDetailed: (string) => void; logDetailed: (string) => void;
logWarning: (string) => void; logWarning: (string) => void;
@ -139,6 +140,25 @@ export async function importData({
const allRecordsCount = await records.getCount(); const allRecordsCount = await records.getCount();
const promises = []; const promises = [];
const ltarPromise = importLTARData({
table,
baseName,
insertedAssocRef,
dataStream,
atNcAliasRef,
ncLinkMappingTable,
syncDB,
source,
services,
logBasic,
logDetailed,
logWarning,
}).catch((e) => {
logWarning(
`There were errors on importing '${table.title}' LTAR data :: ${e}`,
);
});
let tempData = []; let tempData = [];
let importedCount = 0; let importedCount = 0;
let tempCount = 0; let tempCount = 0;
@ -173,6 +193,7 @@ export async function importData({
body: insertArray, body: insertArray,
cookie: {}, cookie: {},
skip_hooks: true, skip_hooks: true,
foreign_key_checks: !!source.isMeta(),
}); });
logBasic( logBasic(
@ -218,6 +239,7 @@ export async function importData({
body: tempData, body: tempData,
cookie: {}, cookie: {},
skip_hooks: true, skip_hooks: true,
foreign_key_checks: !!source.isMeta(),
}); });
logBasic( logBasic(
@ -258,6 +280,7 @@ export async function importLTARData({
atNcAliasRef, atNcAliasRef,
ncLinkMappingTable, ncLinkMappingTable,
syncDB, syncDB,
source,
services, services,
logBasic = (_str) => {}, logBasic = (_str) => {},
logDetailed = (_str) => {}, logDetailed = (_str) => {},
@ -276,6 +299,7 @@ export async function importLTARData({
}; };
ncLinkMappingTable: Record<string, Record<string, any>>[]; ncLinkMappingTable: Record<string, Record<string, any>>[];
syncDB; syncDB;
source: Source;
services: AirtableImportContext; services: AirtableImportContext;
logBasic: (string) => void; logBasic: (string) => void;
logDetailed: (string) => void; logDetailed: (string) => void;
@ -388,6 +412,7 @@ export async function importLTARData({
body: insertArray, body: insertArray,
cookie: {}, cookie: {},
skip_hooks: true, skip_hooks: true,
foreign_key_checks: !!source.isMeta(),
}); });
importedCount += insertArray.length; importedCount += insertArray.length;
@ -426,6 +451,7 @@ export async function importLTARData({
body: assocTableData, body: assocTableData,
cookie: {}, cookie: {},
skip_hooks: true, skip_hooks: true,
foreign_key_checks: !!source.isMeta(),
}); });
importedCount += assocTableData.length; importedCount += assocTableData.length;

Loading…
Cancel
Save