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, sourceType: rest.sourceType || TableSourceType.INTERNAL,
} }
const isImport = !!rows
if (!tableToSave.views) { if (!tableToSave.views) {
tableToSave.views = {} tableToSave.views = {}
} }
@ -35,6 +37,7 @@ export async function save(
rowsToImport: rows, rowsToImport: rows,
tableId: ctx.request.body._id, tableId: ctx.request.body._id,
renaming, renaming,
isImport,
}) })
return table return table

View File

@ -31,6 +31,7 @@ export async function save(
tableId?: string tableId?: string
rowsToImport?: Row[] rowsToImport?: Row[]
renaming?: RenameColumn renaming?: RenameColumn
isImport?: boolean
} }
) { ) {
const db = context.getAppDB() const db = context.getAppDB()
@ -47,7 +48,9 @@ export async function save(
} }
// check for case sensitivity - we don't want to allow duplicated columns // 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) { if (duplicateColumn.length) {
throw new Error( throw new Error(
`Column(s) "${duplicateColumn.join( `Column(s) "${duplicateColumn.join(

View File

@ -53,7 +53,10 @@ export function canBeSortColumn(type: FieldType): boolean {
return !!allowSortColumnByType[type] return !!allowSortColumnByType[type]
} }
export function findDuplicateInternalColumns(table: Table): string[] { export function findDuplicateInternalColumns(
table: Table,
opts?: { ignoreProtectedColumnNames: boolean }
): string[] {
// maintains the case of keys // maintains the case of keys
const casedKeys = Object.keys(table.schema) const casedKeys = Object.keys(table.schema)
// get the column names // get the column names
@ -69,9 +72,11 @@ export function findDuplicateInternalColumns(table: Table): string[] {
} }
} }
} }
for (let internalColumn of CONSTANT_INTERNAL_ROW_COLS) { if (!opts?.ignoreProtectedColumnNames) {
if (casedKeys.find(key => key === internalColumn)) { for (let internalColumn of CONSTANT_INTERNAL_ROW_COLS) {
duplicates.push(internalColumn) if (casedKeys.find(key => key === internalColumn)) {
duplicates.push(internalColumn)
}
} }
} }
return duplicates return duplicates