Allow constant internal columns to be duplicated based on being case sensitive.
This commit is contained in:
parent
7262d8ae93
commit
41f045d8a6
|
@ -285,12 +285,9 @@ describe.each([
|
||||||
type: FieldType.STRING,
|
type: FieldType.STRING,
|
||||||
name: "Type",
|
name: "Type",
|
||||||
}
|
}
|
||||||
|
// allow the "Type" column - internal columns aren't case sensitive
|
||||||
await config.api.table.save(saveTableRequest, {
|
await config.api.table.save(saveTableRequest, {
|
||||||
status: 400,
|
status: 200,
|
||||||
body: {
|
|
||||||
message:
|
|
||||||
'Column(s) "type" are duplicated - check for other columns with these name (case in-sensitive)',
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
saveTableRequest.schema.foo = { type: FieldType.STRING, name: "foo" }
|
saveTableRequest.schema.foo = { type: FieldType.STRING, name: "foo" }
|
||||||
saveTableRequest.schema.FOO = { type: FieldType.STRING, name: "FOO" }
|
saveTableRequest.schema.FOO = { type: FieldType.STRING, name: "FOO" }
|
||||||
|
@ -299,7 +296,7 @@ describe.each([
|
||||||
status: 400,
|
status: 400,
|
||||||
body: {
|
body: {
|
||||||
message:
|
message:
|
||||||
'Column(s) "type, foo" are duplicated - check for other columns with these name (case in-sensitive)',
|
'Column(s) "foo" are duplicated - check for other columns with these name (case in-sensitive)',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -54,20 +54,25 @@ export function canBeSortColumn(type: FieldType): boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function findDuplicateInternalColumns(table: Table): string[] {
|
export function findDuplicateInternalColumns(table: Table): string[] {
|
||||||
|
// maintains the case of keys
|
||||||
|
const casedKeys = Object.keys(table.schema)
|
||||||
// get the column names
|
// get the column names
|
||||||
const columnNames = Object.keys(table.schema)
|
const uncasedKeys = casedKeys.map(colName => colName.toLowerCase())
|
||||||
.concat(CONSTANT_INTERNAL_ROW_COLS)
|
|
||||||
.map(colName => colName.toLowerCase())
|
|
||||||
// there are duplicates
|
// there are duplicates
|
||||||
const set = new Set(columnNames)
|
const set = new Set(uncasedKeys)
|
||||||
let duplicates: string[] = []
|
let duplicates: string[] = []
|
||||||
if (set.size !== columnNames.length) {
|
if (set.size !== uncasedKeys.length) {
|
||||||
for (let key of set.keys()) {
|
for (let key of set.keys()) {
|
||||||
const count = columnNames.filter(name => name === key).length
|
const count = uncasedKeys.filter(name => name === key).length
|
||||||
if (count > 1) {
|
if (count > 1) {
|
||||||
duplicates.push(key)
|
duplicates.push(key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (let internalColumn of CONSTANT_INTERNAL_ROW_COLS) {
|
||||||
|
if (casedKeys.find(key => key === internalColumn)) {
|
||||||
|
duplicates.push(internalColumn)
|
||||||
|
}
|
||||||
|
}
|
||||||
return duplicates
|
return duplicates
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue