Merge pull request #14252 from Budibase/chore/fix-import-table

Fix importing internal tables
This commit is contained in:
Adria Navarro 2024-07-26 14:40:42 +02:00 committed by GitHub
commit 1be7d81072
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 5 deletions

View File

@ -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

View File

@ -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(

View File

@ -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
}