Fixing some issues highlighted by test case.
This commit is contained in:
parent
14266be4e4
commit
3cc4b71561
|
@ -258,11 +258,12 @@ describe("/datasources", () => {
|
|||
})
|
||||
)
|
||||
|
||||
const stringName = "string"
|
||||
const fullSchema: {
|
||||
[type in SupportedSqlTypes]: FieldSchema & { type: type }
|
||||
} = {
|
||||
[FieldType.STRING]: {
|
||||
name: "string",
|
||||
name: stringName,
|
||||
type: FieldType.STRING,
|
||||
constraints: {
|
||||
presence: true,
|
||||
|
@ -353,6 +354,10 @@ describe("/datasources", () => {
|
|||
),
|
||||
schema: Object.entries(table.schema).reduce<TableSchema>(
|
||||
(acc, [fieldName, field]) => {
|
||||
// the constraint will be unset - as the DB doesn't recognise it as not null
|
||||
if (fieldName === stringName) {
|
||||
field.constraints = {}
|
||||
}
|
||||
acc[fieldName] = expect.objectContaining({
|
||||
...field,
|
||||
})
|
||||
|
|
|
@ -289,19 +289,25 @@ function copyExistingPropsOver(
|
|||
externalType:
|
||||
existingTableSchema[key].externalType ||
|
||||
table.schema[key]?.externalType,
|
||||
autocolumn: !!fetchedColumnDefinition?.autocolumn,
|
||||
autocolumn: fetchedColumnDefinition?.autocolumn,
|
||||
} as FieldSchema
|
||||
// check constraints which can be fetched from the DB (they could be updated)
|
||||
if (fetchedColumnDefinition?.constraints) {
|
||||
// inclusions are the enum values (select/options)
|
||||
const fetchedInclusion = fetchedColumnDefinition.constraints.inclusion
|
||||
const oldInclusion = table.schema[key].constraints?.inclusion
|
||||
const fetchedConstraints = fetchedColumnDefinition.constraints
|
||||
const oldConstraints = table.schema[key].constraints
|
||||
table.schema[key].constraints = {
|
||||
...table.schema[key].constraints,
|
||||
presence: !!fetchedColumnDefinition.constraints?.presence,
|
||||
inclusion: fetchedInclusion?.length
|
||||
? fetchedInclusion
|
||||
: oldInclusion,
|
||||
inclusion: fetchedConstraints.inclusion?.length
|
||||
? fetchedConstraints.inclusion
|
||||
: oldConstraints?.inclusion,
|
||||
}
|
||||
// true or undefined - consistent with old API
|
||||
if (fetchedConstraints.presence) {
|
||||
table.schema[key].constraints!.presence =
|
||||
fetchedConstraints.presence
|
||||
} else if (oldConstraints?.presence === true) {
|
||||
delete table.schema[key].constraints?.presence
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue