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: {
|
const fullSchema: {
|
||||||
[type in SupportedSqlTypes]: FieldSchema & { type: type }
|
[type in SupportedSqlTypes]: FieldSchema & { type: type }
|
||||||
} = {
|
} = {
|
||||||
[FieldType.STRING]: {
|
[FieldType.STRING]: {
|
||||||
name: "string",
|
name: stringName,
|
||||||
type: FieldType.STRING,
|
type: FieldType.STRING,
|
||||||
constraints: {
|
constraints: {
|
||||||
presence: true,
|
presence: true,
|
||||||
|
@ -353,6 +354,10 @@ describe("/datasources", () => {
|
||||||
),
|
),
|
||||||
schema: Object.entries(table.schema).reduce<TableSchema>(
|
schema: Object.entries(table.schema).reduce<TableSchema>(
|
||||||
(acc, [fieldName, field]) => {
|
(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({
|
acc[fieldName] = expect.objectContaining({
|
||||||
...field,
|
...field,
|
||||||
})
|
})
|
||||||
|
|
|
@ -289,19 +289,25 @@ function copyExistingPropsOver(
|
||||||
externalType:
|
externalType:
|
||||||
existingTableSchema[key].externalType ||
|
existingTableSchema[key].externalType ||
|
||||||
table.schema[key]?.externalType,
|
table.schema[key]?.externalType,
|
||||||
autocolumn: !!fetchedColumnDefinition?.autocolumn,
|
autocolumn: fetchedColumnDefinition?.autocolumn,
|
||||||
} as FieldSchema
|
} as FieldSchema
|
||||||
// check constraints which can be fetched from the DB (they could be updated)
|
// check constraints which can be fetched from the DB (they could be updated)
|
||||||
if (fetchedColumnDefinition?.constraints) {
|
if (fetchedColumnDefinition?.constraints) {
|
||||||
// inclusions are the enum values (select/options)
|
// inclusions are the enum values (select/options)
|
||||||
const fetchedInclusion = fetchedColumnDefinition.constraints.inclusion
|
const fetchedConstraints = fetchedColumnDefinition.constraints
|
||||||
const oldInclusion = table.schema[key].constraints?.inclusion
|
const oldConstraints = table.schema[key].constraints
|
||||||
table.schema[key].constraints = {
|
table.schema[key].constraints = {
|
||||||
...table.schema[key].constraints,
|
...table.schema[key].constraints,
|
||||||
presence: !!fetchedColumnDefinition.constraints?.presence,
|
inclusion: fetchedConstraints.inclusion?.length
|
||||||
inclusion: fetchedInclusion?.length
|
? fetchedConstraints.inclusion
|
||||||
? fetchedInclusion
|
: oldConstraints?.inclusion,
|
||||||
: oldInclusion,
|
}
|
||||||
|
// 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