diff --git a/packages/server/src/api/routes/tests/datasource.spec.ts b/packages/server/src/api/routes/tests/datasource.spec.ts index f7838b1d39..8fa84ac05d 100644 --- a/packages/server/src/api/routes/tests/datasource.spec.ts +++ b/packages/server/src/api/routes/tests/datasource.spec.ts @@ -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( (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, }) diff --git a/packages/server/src/integrations/utils/utils.ts b/packages/server/src/integrations/utils/utils.ts index 41e62f8975..b97782ce7e 100644 --- a/packages/server/src/integrations/utils/utils.ts +++ b/packages/server/src/integrations/utils/utils.ts @@ -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 } } }