From a879b5814ab3191eb224bb49c3795d08b6eb7846 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 7 Jun 2024 16:57:33 +0100 Subject: [PATCH] Making sure that columns get updated to allow nulls/disallow correctly, as well as making sure enums can be updated and autocolumn state can change. --- packages/server/src/integrations/utils/utils.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/server/src/integrations/utils/utils.ts b/packages/server/src/integrations/utils/utils.ts index 157bdba3bd..41e62f8975 100644 --- a/packages/server/src/integrations/utils/utils.ts +++ b/packages/server/src/integrations/utils/utils.ts @@ -280,12 +280,29 @@ function copyExistingPropsOver( utils.unreachable(existingColumnType) } + // copy the BB schema in case of special props if (shouldKeepSchema) { + const fetchedColumnDefinition: FieldSchema | undefined = + table.schema[key] table.schema[key] = { ...existingTableSchema[key], externalType: existingTableSchema[key].externalType || table.schema[key]?.externalType, + 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 + table.schema[key].constraints = { + ...table.schema[key].constraints, + presence: !!fetchedColumnDefinition.constraints?.presence, + inclusion: fetchedInclusion?.length + ? fetchedInclusion + : oldInclusion, + } } } }