Addressing PR comments.
This commit is contained in:
parent
fead1f436a
commit
b4910043c6
|
@ -54,7 +54,6 @@
|
|||
const DATE_TYPE = FieldType.DATETIME
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
const PROHIBITED_COLUMN_NAMES = ["type", "_id", "_rev", "tableId"]
|
||||
const { dispatch: gridDispatch, rows } = getContext("grid")
|
||||
|
||||
export let field
|
||||
|
|
|
@ -289,18 +289,17 @@ describe.each([
|
|||
status: 400,
|
||||
body: {
|
||||
message:
|
||||
'Column "type" is duplicated - make sure there are no duplicate columns names, this is case insensitive.',
|
||||
'Column(s) "type" are duplicated - check for other columns with these name (case in-sensitive)',
|
||||
},
|
||||
})
|
||||
saveTableRequest.schema = {
|
||||
foo: { type: FieldType.STRING, name: "foo" },
|
||||
FOO: { type: FieldType.STRING, name: "FOO" },
|
||||
}
|
||||
saveTableRequest.schema.foo = { type: FieldType.STRING, name: "foo" }
|
||||
saveTableRequest.schema.FOO = { type: FieldType.STRING, name: "FOO" }
|
||||
|
||||
await config.api.table.save(saveTableRequest, {
|
||||
status: 400,
|
||||
body: {
|
||||
message:
|
||||
'Column "foo" is duplicated - make sure there are no duplicate columns names, this is case insensitive.',
|
||||
'Column(s) "type, foo" are duplicated - check for other columns with these name (case in-sensitive)',
|
||||
},
|
||||
})
|
||||
})
|
||||
|
|
|
@ -16,7 +16,7 @@ import { EventType, updateLinks } from "../../../../db/linkedRows"
|
|||
import { cloneDeep } from "lodash/fp"
|
||||
import isEqual from "lodash/isEqual"
|
||||
import { runStaticFormulaChecks } from "../../../../api/controllers/table/bulkFormula"
|
||||
import { context, db as dbCore } from "@budibase/backend-core"
|
||||
import { context } from "@budibase/backend-core"
|
||||
import { findDuplicateInternalColumns } from "@budibase/shared-core"
|
||||
import { getTable } from "../getters"
|
||||
import { checkAutoColumns } from "./utils"
|
||||
|
@ -48,9 +48,11 @@ export async function save(
|
|||
|
||||
// check for case sensitivity - we don't want to allow duplicated columns
|
||||
const duplicateColumn = findDuplicateInternalColumns(table)
|
||||
if (duplicateColumn) {
|
||||
if (duplicateColumn.length) {
|
||||
throw new Error(
|
||||
`Column "${duplicateColumn}" is duplicated - make sure there are no duplicate columns names, this is case insensitive.`
|
||||
`Column(s) "${duplicateColumn.join(
|
||||
", "
|
||||
)}" are duplicated - check for other columns with these name (case in-sensitive)`
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -53,21 +53,21 @@ export function canBeSortColumn(type: FieldType): boolean {
|
|||
return !!allowSortColumnByType[type]
|
||||
}
|
||||
|
||||
export function findDuplicateInternalColumns(table: Table): string | undefined {
|
||||
export function findDuplicateInternalColumns(table: Table): string[] {
|
||||
// get the column names
|
||||
const columnNames = Object.keys(table.schema)
|
||||
.concat(CONSTANT_INTERNAL_ROW_COLS)
|
||||
.map(colName => colName.toLowerCase())
|
||||
// there are duplicates
|
||||
const set = new Set(columnNames)
|
||||
let foundDuplicate: string | undefined
|
||||
let duplicates: string[] = []
|
||||
if (set.size !== columnNames.length) {
|
||||
for (let key of set.keys()) {
|
||||
const count = columnNames.filter(name => name === key).length
|
||||
if (count > 1) {
|
||||
foundDuplicate = key
|
||||
duplicates.push(key)
|
||||
}
|
||||
}
|
||||
}
|
||||
return foundDuplicate
|
||||
return duplicates
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue