Protect serverless migration metadata operations interacting with metadata (#12739)

# 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
This commit is contained in:
Paul Rastoin
2025-06-19 17:09:14 +02:00
committed by GitHub
parent 6d56b75962
commit 5c118b91ac

View File

@ -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"`,