From 5c118b91ac21083debd915bdd43ffe2f0f216224 Mon Sep 17 00:00:00 2001 From: Paul Rastoin <45004772+prastoin@users.noreply.github.com> Date: Thu, 19 Jun 2025 17:09:14 +0200 Subject: [PATCH] Protect serverless migration metadata operations interacting with metadata (#12739) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Introduction This migration has been introduced in 0.54 we should determine how we wanna handle retro-compatibility with this, might not wanna merge this one latest main 🤔 but only a new 0.54 patch related to https://github.com/twentyhq/twenty/issues/12651#issuecomment-2988164122 ## Concerns If a workspace fails this migration that's not a good sign, the metadata schema should be completely empty since 0.54 `metadata` merge into `core` migration. Please review you existing entries in the schema and verify they exists in the dest `core` one --- ...8-removeUselessServerlessFunctionColumn.ts | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/packages/twenty-server/src/database/typeorm/core/migrations/common/1748942397538-removeUselessServerlessFunctionColumn.ts b/packages/twenty-server/src/database/typeorm/core/migrations/common/1748942397538-removeUselessServerlessFunctionColumn.ts index 535fdbda3..f31f8400e 100644 --- a/packages/twenty-server/src/database/typeorm/core/migrations/common/1748942397538-removeUselessServerlessFunctionColumn.ts +++ b/packages/twenty-server/src/database/typeorm/core/migrations/common/1748942397538-removeUselessServerlessFunctionColumn.ts @@ -15,13 +15,27 @@ export class RemoveUselessServerlessFunctionColumn1748942397538 ); if (metadataSchemaExists && metadataSchemaExists.length > 0) { - await queryRunner.query(` - ALTER TYPE "metadata"."dataSource_type_enum" SET SCHEMA "core"; - ALTER TYPE "metadata"."indexMetadata_indextype_enum" SET SCHEMA "core"; - ALTER TYPE "metadata"."relationMetadata_ondeleteaction_enum" SET SCHEMA "core"; - ALTER TYPE "metadata"."serverlessFunction_syncstatus_enum" SET SCHEMA "core"; - - `); + const potentialTypeNameToMigrate = [ + 'dataSource_type_enum', + 'indexMetadata_indextype_enum', + 'relationMetadata_ondeleteaction_enum', + 'serverlessFunction_syncstatus_enum', + ] as const; + + for (const typeName of potentialTypeNameToMigrate) { + const selectResult = await queryRunner.query( + `SELECT 1 FROM information_schema.types WHERE type_schema = 'metadata' AND type_name = '${typeName}';`, + ); + const typeNameExists = selectResult && selectResult.length > 0; + + if (!typeNameExists) { + continue; + } + + await queryRunner.query( + `ALTER TYPE "metadata"."${typeName}" SET SCHEMA "core";`, + ); + } } await queryRunner.query( `DROP TYPE "core"."serverlessFunction_syncstatus_enum"`,