1
0
Fork 0
mirror of synced 2024-08-05 13:21:26 +12:00

Fixing some issues highlighted by test case.

This commit is contained in:
mike12345567 2024-06-07 17:59:18 +01:00
parent 14266be4e4
commit 3cc4b71561
2 changed files with 19 additions and 8 deletions

View file

@ -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,
})

View file

@ -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
}
}
}