Skip to content

Commit 03fe060

Browse files
prastoinabdulrahmancodes
authored andcommitted
Protect serverless migration metadata operations interacting with metadata (twentyhq#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 twentyhq#12651 (comment) ## 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
1 parent 5191821 commit 03fe060

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

packages/twenty-server/src/database/typeorm/core/migrations/common/1748942397538-removeUselessServerlessFunctionColumn.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,27 @@ export class RemoveUselessServerlessFunctionColumn1748942397538
1515
);
1616

1717
if (metadataSchemaExists && metadataSchemaExists.length > 0) {
18-
await queryRunner.query(`
19-
ALTER TYPE "metadata"."dataSource_type_enum" SET SCHEMA "core";
20-
ALTER TYPE "metadata"."indexMetadata_indextype_enum" SET SCHEMA "core";
21-
ALTER TYPE "metadata"."relationMetadata_ondeleteaction_enum" SET SCHEMA "core";
22-
ALTER TYPE "metadata"."serverlessFunction_syncstatus_enum" SET SCHEMA "core";
23-
24-
`);
18+
const potentialTypeNameToMigrate = [
19+
'dataSource_type_enum',
20+
'indexMetadata_indextype_enum',
21+
'relationMetadata_ondeleteaction_enum',
22+
'serverlessFunction_syncstatus_enum',
23+
] as const;
24+
25+
for (const typeName of potentialTypeNameToMigrate) {
26+
const selectResult = await queryRunner.query(
27+
`SELECT 1 FROM information_schema.types WHERE type_schema = 'metadata' AND type_name = '${typeName}';`,
28+
);
29+
const typeNameExists = selectResult && selectResult.length > 0;
30+
31+
if (!typeNameExists) {
32+
continue;
33+
}
34+
35+
await queryRunner.query(
36+
`ALTER TYPE "metadata"."${typeName}" SET SCHEMA "core";`,
37+
);
38+
}
2539
}
2640
await queryRunner.query(
2741
`DROP TYPE "core"."serverlessFunction_syncstatus_enum"`,

0 commit comments

Comments
 (0)