Fix bulk import to not modify the table schema.

This commit is contained in:
Sam Rose 2024-09-25 16:44:37 +01:00
parent 564e16fd5c
commit 566af9e454
No known key found for this signature in database
2 changed files with 13 additions and 18 deletions

View File

@ -70,22 +70,10 @@ export async function bulkImport(
) {
const table = await sdk.tables.getTable(ctx.params.tableId)
const { rows, identifierFields } = ctx.request.body
await handleDataImport(
{
...table,
schema: {
_id: {
name: "_id",
type: FieldType.STRING,
},
...table.schema,
},
},
{
importRows: rows,
identifierFields,
user: ctx.user,
}
)
await handleDataImport(table, {
importRows: rows,
identifierFields,
user: ctx.user,
})
return table
}

View File

@ -148,9 +148,16 @@ export function parse(rows: Rows, table: Table): Rows {
Object.keys(row).forEach(columnName => {
const columnData = row[columnName]
if (columnName === "_id") {
parsedRow[columnName] = columnData
return
}
const schema = table.schema
if (!(columnName in schema)) {
// Objects can be present in the row data but not in the schema, so make sure we don't proceed in such a case
// Objects can be present in the row data but not in the schema, so make
// sure we don't proceed in such a case
return
}