Merge pull request #14252 from Budibase/chore/fix-import-table
Fix importing internal tables
This commit is contained in:
commit
1be7d81072
|
@ -25,6 +25,8 @@ export async function save(
|
|||
sourceType: rest.sourceType || TableSourceType.INTERNAL,
|
||||
}
|
||||
|
||||
const isImport = !!rows
|
||||
|
||||
if (!tableToSave.views) {
|
||||
tableToSave.views = {}
|
||||
}
|
||||
|
@ -35,6 +37,7 @@ export async function save(
|
|||
rowsToImport: rows,
|
||||
tableId: ctx.request.body._id,
|
||||
renaming,
|
||||
isImport,
|
||||
})
|
||||
|
||||
return table
|
||||
|
|
|
@ -31,6 +31,7 @@ export async function save(
|
|||
tableId?: string
|
||||
rowsToImport?: Row[]
|
||||
renaming?: RenameColumn
|
||||
isImport?: boolean
|
||||
}
|
||||
) {
|
||||
const db = context.getAppDB()
|
||||
|
@ -47,7 +48,9 @@ export async function save(
|
|||
}
|
||||
|
||||
// check for case sensitivity - we don't want to allow duplicated columns
|
||||
const duplicateColumn = findDuplicateInternalColumns(table)
|
||||
const duplicateColumn = findDuplicateInternalColumns(table, {
|
||||
ignoreProtectedColumnNames: !oldTable && !!opts?.isImport,
|
||||
})
|
||||
if (duplicateColumn.length) {
|
||||
throw new Error(
|
||||
`Column(s) "${duplicateColumn.join(
|
||||
|
|
|
@ -53,7 +53,10 @@ export function canBeSortColumn(type: FieldType): boolean {
|
|||
return !!allowSortColumnByType[type]
|
||||
}
|
||||
|
||||
export function findDuplicateInternalColumns(table: Table): string[] {
|
||||
export function findDuplicateInternalColumns(
|
||||
table: Table,
|
||||
opts?: { ignoreProtectedColumnNames: boolean }
|
||||
): string[] {
|
||||
// maintains the case of keys
|
||||
const casedKeys = Object.keys(table.schema)
|
||||
// get the column names
|
||||
|
@ -69,10 +72,12 @@ export function findDuplicateInternalColumns(table: Table): string[] {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!opts?.ignoreProtectedColumnNames) {
|
||||
for (let internalColumn of CONSTANT_INTERNAL_ROW_COLS) {
|
||||
if (casedKeys.find(key => key === internalColumn)) {
|
||||
duplicates.push(internalColumn)
|
||||
}
|
||||
}
|
||||
}
|
||||
return duplicates
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue