Browse Source

Merge pull request #7391 from nocodb/nc-fix/dg-at-import

fix: various at import issues
pull/7394/head
Mert E 10 months ago committed by GitHub
parent
commit
9d52187d1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 121
      packages/nocodb/src/modules/jobs/jobs/at-import/at-import.processor.ts
  2. 12
      packages/nocodb/src/modules/jobs/jobs/at-import/helpers/fetchAT.ts
  3. 11
      packages/nocodb/src/services/tables.service.ts

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

@ -146,6 +146,11 @@ export class AtImportProcessor {
this.debugLog(log); this.debugLog(log);
}; };
const logWarning = (log) => {
this.jobsLogService.sendLog(job, { message: `WARNING: ${log}` });
this.debugLog(log);
};
const logDetailed = (log) => { const logDetailed = (log) => {
if (debugMode) this.jobsLogService.sendLog(job, { message: log }); if (debugMode) this.jobsLogService.sendLog(job, { message: log });
this.debugLog(log); this.debugLog(log);
@ -291,7 +296,7 @@ export class AtImportProcessor {
rating: UITypes.Rating, rating: UITypes.Rating,
formula: UITypes.Formula, formula: UITypes.Formula,
rollup: UITypes.Rollup, rollup: UITypes.Rollup,
count: UITypes.Count, count: UITypes.Rollup,
lookup: UITypes.Lookup, lookup: UITypes.Lookup,
autoNumber: UITypes.AutoNumber, autoNumber: UITypes.AutoNumber,
barcode: UITypes.SingleLineText, barcode: UITypes.SingleLineText,
@ -430,19 +435,14 @@ export class AtImportProcessor {
if ((value as any).name === '') { if ((value as any).name === '') {
(value as any).name = 'nc_empty'; (value as any).name = 'nc_empty';
} }
// enumerate duplicates (we don't allow them) // skip duplicates (we don't allow them)
// TODO fix record mapping (this causes every record to map first option, if (
// we can't handle them using data api as they don't provide option id
// within data we might instead get the correct mapping from schema file )
let dupNo = 1;
const defaultName = (value as any).name;
while (
options.find( options.find(
(el) => (el) =>
el.title.toLowerCase() === (value as any).name.toLowerCase(), el.title.toLowerCase() === (value as any).name.toLowerCase(),
) )
) { ) {
(value as any).name = `${defaultName}_${dupNo++}`; continue;
} }
options.push({ options.push({
order: order++, order: order++,
@ -865,15 +865,6 @@ export class AtImportProcessor {
); );
} }
// check if already a column exists with this name?
const duplicate = childTblSchema.columns.find(
(x) => x.title === aTblLinkColumns[i].name,
);
const suffix = duplicate ? '_2' : '';
if (duplicate)
if (enableErrorLogs)
console.log(`## Duplicate ${aTblLinkColumns[i].name}`);
// rename // rename
// note that: current rename API requires us to send all parameters, // note that: current rename API requires us to send all parameters,
// not just title being renamed // not just title being renamed
@ -900,12 +891,12 @@ export class AtImportProcessor {
updateNcTblSchema(ncTbl); updateNcTblSchema(ncTbl);
const ncId = ncTbl.columns.find( const ncId = ncTbl.columns.find(
(x) => x.title === aTblLinkColumns[i].name + suffix, (x) => x.title === ncName.title,
)?.id; )?.id;
await sMap.addToMappingTbl( await sMap.addToMappingTbl(
aTblLinkColumns[i].id, aTblLinkColumns[i].id,
ncId, ncId,
aTblLinkColumns[i].name + suffix, ncName.title,
ncTbl.id, ncTbl.id,
); );
} }
@ -1100,7 +1091,7 @@ export class AtImportProcessor {
ARRAYCOMPACT: '', ARRAYCOMPACT: '',
ARRAYJOIN: '', ARRAYJOIN: '',
ARRAYUNIQUE: '', ARRAYUNIQUE: '',
AVERAGE: 'average', AVERAGE: 'avg',
CONCATENATE: '', CONCATENATE: '',
COUNT: 'count', COUNT: 'count',
COUNTA: '', COUNTA: '',
@ -1206,35 +1197,41 @@ export class AtImportProcessor {
logDetailed(`NC API: dbTableColumn.create ROLLUP ${ncName.title}`); logDetailed(`NC API: dbTableColumn.create ROLLUP ${ncName.title}`);
const _perfStart = recordPerfStart(); const _perfStart = recordPerfStart();
const ncTbl: any = await this.columnsService.columnAdd({ try {
tableId: srcTableId, const ncTbl: any = await this.columnsService.columnAdd({
column: { tableId: srcTableId,
uidt: UITypes.Rollup, column: {
title: ncName.title, uidt: UITypes.Rollup,
column_name: ncName.column_name, title: ncName.title,
fk_relation_column_id: ncRelationColumnId, column_name: ncName.column_name,
fk_rollup_column_id: ncRollupColumnId, fk_relation_column_id: ncRelationColumnId,
rollup_function: ncRollupFn, fk_rollup_column_id: ncRollupColumnId,
}, rollup_function: ncRollupFn,
req: { },
user: syncDB.user.email, req: {
clientIp: '', user: syncDB.user.email,
}, clientIp: '',
user: syncDB.user, },
}); user: syncDB.user,
recordPerfStats(_perfStart, 'dbTableColumn.create'); });
recordPerfStats(_perfStart, 'dbTableColumn.create');
updateNcTblSchema(ncTbl); updateNcTblSchema(ncTbl);
const ncId = ncTbl.columns.find( const ncId = ncTbl.columns.find(
(x) => x.title === aTblColumns[i].name, (x) => x.title === aTblColumns[i].name,
)?.id; )?.id;
await sMap.addToMappingTbl( await sMap.addToMappingTbl(
aTblColumns[i].id, aTblColumns[i].id,
ncId, ncId,
aTblColumns[i].name, aTblColumns[i].name,
ncTbl.id, ncTbl.id,
); );
} catch (e) {
logWarning(
`Skipped creating rollup column ${aTblColumns[i].name} :: ${e.message}`,
);
}
} }
} }
} }
@ -1812,9 +1809,14 @@ export class AtImportProcessor {
}, },
req: { user: syncDB.user, clientIp: '' }, req: { user: syncDB.user, clientIp: '' },
}) })
.catch((e) => .catch((e) => {
e.message ? logBasic(`NOTICE: ${e.message}`) : console.log(e), if (e.message) {
), // TODO enable after fixing user invite role issue
// logWarning(e.message);
} else {
console.log(e);
}
}),
); );
recordPerfStats(_perfStart, 'auth.baseUserAdd'); recordPerfStats(_perfStart, 'auth.baseUserAdd');
} }
@ -2106,12 +2108,16 @@ export class AtImportProcessor {
// insert filters // insert filters
for (let i = 0; i < ncFilters.length; i++) { for (let i = 0; i < ncFilters.length; i++) {
const _perfStart = recordPerfStart(); const _perfStart = recordPerfStart();
await this.filtersService.filterCreate({ try {
viewId: viewId, await this.filtersService.filterCreate({
filter: ncFilters[i], viewId: viewId,
user: syncDB.user, filter: ncFilters[i],
req: {}, user: syncDB.user,
}); req: {},
});
} catch (e) {
logWarning(`Skipped creating filter for ${viewId} :: ${e.message}`);
}
recordPerfStats(_perfStart, 'dbTableFilter.create'); recordPerfStats(_perfStart, 'dbTableFilter.create');
rtc.filter++; rtc.filter++;
@ -2498,6 +2504,7 @@ export class AtImportProcessor {
await this.tablesService.tableDelete({ await this.tablesService.tableDelete({
tableId: table.id, tableId: table.id,
user: syncDB.user, user: syncDB.user,
forceDeleteRelations: true,
}); });
} }
if (e.message) { if (e.message) {

12
packages/nocodb/src/modules/jobs/jobs/at-import/helpers/fetchAT.ts

@ -50,12 +50,24 @@ async function initialize(shareId, appId?: string) {
}; };
}); });
const headers = hreq.match(/(?<=var headers =)(.*)(?=;)/g);
const link = hreq.match(/(?<=fetch\(")(\\.*)(?=")/g);
if (!headers || !link) {
throw {
message:
'Please ensure www.airtable.com/<SharedBaseID> is available for public access. Refer https://bit.ly/3x0OdXI for details',
};
}
info.headers = JSON.parse( info.headers = JSON.parse(
hreq.match(/(?<=var headers =)(.*)(?=;)/g)[0].trim(), hreq.match(/(?<=var headers =)(.*)(?=;)/g)[0].trim(),
); );
info.link = unicodeToChar( info.link = unicodeToChar(
hreq.match(/(?<=fetch\(")(\\.*)(?=")/g)[0].trim(), hreq.match(/(?<=fetch\(")(\\.*)(?=")/g)[0].trim(),
); );
info.baseInfo = decodeURIComponent(info.link) info.baseInfo = decodeURIComponent(info.link)
.match(/{(.*)}/g)[0] .match(/{(.*)}/g)[0]
.split('&') .split('&')

11
packages/nocodb/src/services/tables.service.ts

@ -162,7 +162,12 @@ export class TablesService {
return Model.updateOrder(param.tableId, param.order); return Model.updateOrder(param.tableId, param.order);
} }
async tableDelete(param: { tableId: string; user: User; req?: any }) { async tableDelete(param: {
tableId: string;
user: User;
forceDeleteRelations?: boolean;
req?: any;
}) {
const table = await Model.getByIdOrName({ id: param.tableId }); const table = await Model.getByIdOrName({ id: param.tableId });
await table.getColumns(); await table.getColumns();
@ -171,7 +176,9 @@ export class TablesService {
const relationColumns = table.columns.filter((c) => isLinksOrLTAR(c)); const relationColumns = table.columns.filter((c) => isLinksOrLTAR(c));
if (relationColumns?.length && !source.isMeta()) { const deleteRelations = source.isMeta() || param.forceDeleteRelations;
if (relationColumns?.length && !deleteRelations) {
const referredTables = await Promise.all( const referredTables = await Promise.all(
relationColumns.map(async (c) => relationColumns.map(async (c) =>
c c

Loading…
Cancel
Save