|
|
@ -1,6 +1,7 @@ |
|
|
|
/* eslint-disable no-async-promise-executor */ |
|
|
|
/* eslint-disable no-async-promise-executor */ |
|
|
|
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 EntityMap from './EntityMap'; |
|
|
|
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'; |
|
|
@ -8,6 +9,8 @@ import type { TablesService } from '../../../../../services/tables.service'; |
|
|
|
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'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const logger = new Logger('BaseModelSqlv2'); |
|
|
|
|
|
|
|
|
|
|
|
const BULK_DATA_BATCH_COUNT = 20; // check size for every 100 records
|
|
|
|
const BULK_DATA_BATCH_COUNT = 20; // check size for every 100 records
|
|
|
|
const BULK_DATA_BATCH_SIZE = 50 * 1024; // in bytes
|
|
|
|
const BULK_DATA_BATCH_SIZE = 50 * 1024; // in bytes
|
|
|
|
const BULK_LINK_BATCH_COUNT = 1000; // process 1000 records at a time
|
|
|
|
const BULK_LINK_BATCH_COUNT = 1000; // process 1000 records at a time
|
|
|
@ -23,14 +26,16 @@ async function readAllData({ |
|
|
|
fields, |
|
|
|
fields, |
|
|
|
atBase, |
|
|
|
atBase, |
|
|
|
logBasic = (_str) => {}, |
|
|
|
logBasic = (_str) => {}, |
|
|
|
|
|
|
|
logWarning = (_str) => {}, |
|
|
|
}: { |
|
|
|
}: { |
|
|
|
table: { title?: string }; |
|
|
|
table: { title?: string }; |
|
|
|
fields?; |
|
|
|
fields?; |
|
|
|
atBase: AirtableBase; |
|
|
|
atBase: AirtableBase; |
|
|
|
logBasic?: (string) => void; |
|
|
|
logBasic?: (string) => void; |
|
|
|
logDetailed?: (string) => void; |
|
|
|
logDetailed?: (string) => void; |
|
|
|
|
|
|
|
logWarning?: (string) => void; |
|
|
|
}): Promise<EntityMap> { |
|
|
|
}): Promise<EntityMap> { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
return new Promise((resolve) => { |
|
|
|
let data = null; |
|
|
|
let data = null; |
|
|
|
|
|
|
|
|
|
|
|
const selectParams: any = { |
|
|
|
const selectParams: any = { |
|
|
@ -74,8 +79,10 @@ async function readAllData({ |
|
|
|
}, |
|
|
|
}, |
|
|
|
async function done(err) { |
|
|
|
async function done(err) { |
|
|
|
if (err) { |
|
|
|
if (err) { |
|
|
|
console.error(err); |
|
|
|
logger.error(err); |
|
|
|
return reject(err); |
|
|
|
logWarning( |
|
|
|
|
|
|
|
`There were errors on reading '${table.title}' data :: ${err}`, |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
resolve(data); |
|
|
|
resolve(data); |
|
|
|
}, |
|
|
|
}, |
|
|
@ -89,8 +96,9 @@ export async function importData({ |
|
|
|
atBase, |
|
|
|
atBase, |
|
|
|
nocoBaseDataProcessing_v2, |
|
|
|
nocoBaseDataProcessing_v2, |
|
|
|
sDB, |
|
|
|
sDB, |
|
|
|
logDetailed = (_str) => {}, |
|
|
|
|
|
|
|
logBasic = (_str) => {}, |
|
|
|
logBasic = (_str) => {}, |
|
|
|
|
|
|
|
logDetailed = (_str) => {}, |
|
|
|
|
|
|
|
logWarning = (_str) => {}, |
|
|
|
services, |
|
|
|
services, |
|
|
|
}: { |
|
|
|
}: { |
|
|
|
baseName: string; |
|
|
|
baseName: string; |
|
|
@ -99,6 +107,7 @@ export async function importData({ |
|
|
|
atBase: AirtableBase; |
|
|
|
atBase: AirtableBase; |
|
|
|
logBasic: (string) => void; |
|
|
|
logBasic: (string) => void; |
|
|
|
logDetailed: (string) => void; |
|
|
|
logDetailed: (string) => void; |
|
|
|
|
|
|
|
logWarning: (string) => void; |
|
|
|
nocoBaseDataProcessing_v2; |
|
|
|
nocoBaseDataProcessing_v2; |
|
|
|
sDB; |
|
|
|
sDB; |
|
|
|
services: AirtableImportContext; |
|
|
|
services: AirtableImportContext; |
|
|
@ -112,7 +121,7 @@ export async function importData({ |
|
|
|
logBasic, |
|
|
|
logBasic, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
await new Promise(async (resolve, reject) => { |
|
|
|
await new Promise(async (resolve) => { |
|
|
|
const readable = records.getStream(); |
|
|
|
const readable = records.getStream(); |
|
|
|
const allRecordsCount = await records.getCount(); |
|
|
|
const allRecordsCount = await records.getCount(); |
|
|
|
const promises = []; |
|
|
|
const promises = []; |
|
|
@ -126,7 +135,7 @@ export async function importData({ |
|
|
|
|
|
|
|
|
|
|
|
readable.on('data', async (record) => { |
|
|
|
readable.on('data', async (record) => { |
|
|
|
promises.push( |
|
|
|
promises.push( |
|
|
|
new Promise(async (resolve, reject) => { |
|
|
|
new Promise(async (resolve) => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
activeProcess++; |
|
|
|
activeProcess++; |
|
|
|
if (activeProcess >= BULK_PARALLEL_PROCESS) readable.pause(); |
|
|
|
if (activeProcess >= BULK_PARALLEL_PROCESS) readable.pause(); |
|
|
@ -173,7 +182,12 @@ export async function importData({ |
|
|
|
if (activeProcess < BULK_PARALLEL_PROCESS) readable.resume(); |
|
|
|
if (activeProcess < BULK_PARALLEL_PROCESS) readable.resume(); |
|
|
|
resolve(true); |
|
|
|
resolve(true); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
reject(e); |
|
|
|
logger.error(e); |
|
|
|
|
|
|
|
logWarning( |
|
|
|
|
|
|
|
`There were errors on importing '${table.title}' data :: ${e}`, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
readable.resume(); |
|
|
|
|
|
|
|
resolve(true); |
|
|
|
} |
|
|
|
} |
|
|
|
}), |
|
|
|
}), |
|
|
|
); |
|
|
|
); |
|
|
@ -206,7 +220,11 @@ export async function importData({ |
|
|
|
} |
|
|
|
} |
|
|
|
resolve(true); |
|
|
|
resolve(true); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
return reject(e); |
|
|
|
logger.error(e); |
|
|
|
|
|
|
|
logWarning( |
|
|
|
|
|
|
|
`There were errors on importing '${table.title}' data :: ${e}`, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
resolve(true); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
@ -223,20 +241,19 @@ export async function importLTARData({ |
|
|
|
atBase, |
|
|
|
atBase, |
|
|
|
baseName, |
|
|
|
baseName, |
|
|
|
insertedAssocRef = {}, |
|
|
|
insertedAssocRef = {}, |
|
|
|
logDetailed = (_str) => {}, |
|
|
|
|
|
|
|
logBasic = (_str) => {}, |
|
|
|
|
|
|
|
records, |
|
|
|
records, |
|
|
|
atNcAliasRef, |
|
|
|
atNcAliasRef, |
|
|
|
ncLinkMappingTable, |
|
|
|
ncLinkMappingTable, |
|
|
|
syncDB, |
|
|
|
syncDB, |
|
|
|
services, |
|
|
|
services, |
|
|
|
|
|
|
|
logBasic = (_str) => {}, |
|
|
|
|
|
|
|
logDetailed = (_str) => {}, |
|
|
|
|
|
|
|
logWarning = (_str) => {}, |
|
|
|
}: { |
|
|
|
}: { |
|
|
|
baseName: string; |
|
|
|
baseName: string; |
|
|
|
table: { title?: string; id?: string }; |
|
|
|
table: { title?: string; id?: string }; |
|
|
|
fields; |
|
|
|
fields; |
|
|
|
atBase: AirtableBase; |
|
|
|
atBase: AirtableBase; |
|
|
|
logDetailed: (string) => void; |
|
|
|
|
|
|
|
logBasic: (string) => void; |
|
|
|
|
|
|
|
insertedAssocRef: { [assocTableId: string]: boolean }; |
|
|
|
insertedAssocRef: { [assocTableId: string]: boolean }; |
|
|
|
records?: EntityMap; |
|
|
|
records?: EntityMap; |
|
|
|
atNcAliasRef: { |
|
|
|
atNcAliasRef: { |
|
|
@ -247,6 +264,9 @@ export async function importLTARData({ |
|
|
|
ncLinkMappingTable: Record<string, Record<string, any>>[]; |
|
|
|
ncLinkMappingTable: Record<string, Record<string, any>>[]; |
|
|
|
syncDB; |
|
|
|
syncDB; |
|
|
|
services: AirtableImportContext; |
|
|
|
services: AirtableImportContext; |
|
|
|
|
|
|
|
logBasic: (string) => void; |
|
|
|
|
|
|
|
logDetailed: (string) => void; |
|
|
|
|
|
|
|
logWarning: (string) => void; |
|
|
|
}) { |
|
|
|
}) { |
|
|
|
const assocTableMetas: Array<{ |
|
|
|
const assocTableMetas: Array<{ |
|
|
|
modelMeta: { id?: string; title?: string }; |
|
|
|
modelMeta: { id?: string; title?: string }; |
|
|
@ -313,7 +333,7 @@ export async function importLTARData({ |
|
|
|
// Iterate over all related M2M associative table
|
|
|
|
// Iterate over all related M2M associative table
|
|
|
|
for (const assocMeta of assocTableMetas) { |
|
|
|
for (const assocMeta of assocTableMetas) { |
|
|
|
// extract link data from records
|
|
|
|
// extract link data from records
|
|
|
|
await new Promise((resolve, reject) => { |
|
|
|
await new Promise((resolve) => { |
|
|
|
const promises = []; |
|
|
|
const promises = []; |
|
|
|
const readable = allData.getStream(); |
|
|
|
const readable = allData.getStream(); |
|
|
|
|
|
|
|
|
|
|
@ -364,7 +384,12 @@ export async function importLTARData({ |
|
|
|
} |
|
|
|
} |
|
|
|
resolve(true); |
|
|
|
resolve(true); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
reject(e); |
|
|
|
logger.error(e); |
|
|
|
|
|
|
|
logWarning( |
|
|
|
|
|
|
|
`There were errors on importing '${table.title}' LTAR data :: ${e}`, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
readable.resume(); |
|
|
|
|
|
|
|
resolve(true); |
|
|
|
} |
|
|
|
} |
|
|
|
}), |
|
|
|
}), |
|
|
|
); |
|
|
|
); |
|
|
@ -398,7 +423,11 @@ export async function importLTARData({ |
|
|
|
|
|
|
|
|
|
|
|
resolve(true); |
|
|
|
resolve(true); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
reject(e); |
|
|
|
logger.error(e); |
|
|
|
|
|
|
|
logWarning( |
|
|
|
|
|
|
|
`There were errors on importing '${table.title}' LTAR data :: ${e}`, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
resolve(true); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|