Allow importing internal tables

This commit is contained in:
Adria Navarro 2024-07-26 13:27:51 +02:00
parent afd9ad9d8d
commit a05ec1498f
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, {
internalRowsAllowed: !!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?: { internalRowsAllowed: boolean }
): string[] {
// maintains the case of keys
const casedKeys = Object.keys(table.schema)
// get the column names
@ -69,9 +72,11 @@ export function findDuplicateInternalColumns(table: Table): string[] {
}
}
}
for (let internalColumn of CONSTANT_INTERNAL_ROW_COLS) {
if (casedKeys.find(key => key === internalColumn)) {
duplicates.push(internalColumn)
if (!opts?.internalRowsAllowed) {
for (let internalColumn of CONSTANT_INTERNAL_ROW_COLS) {
if (casedKeys.find(key => key === internalColumn)) {
duplicates.push(internalColumn)
}
}
}
return duplicates