From 942281f4b04c06188344a5e58a6b67bcf45ef230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Bosi?= <71827178+bosiraphael@users.noreply.github.com> Date: Fri, 27 Sep 2024 17:20:15 +0200 Subject: [PATCH] Fix email migration (#7298) Checks if person standard email field exists before running the migration. --- ...-migrate-email-fields-to-emails.command.ts | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/twenty-server/src/database/commands/upgrade-version/0-30/0-30-migrate-email-fields-to-emails.command.ts b/packages/twenty-server/src/database/commands/upgrade-version/0-30/0-30-migrate-email-fields-to-emails.command.ts index 87ff3e5b0..2e4969297 100644 --- a/packages/twenty-server/src/database/commands/upgrade-version/0-30/0-30-migrate-email-fields-to-emails.command.ts +++ b/packages/twenty-server/src/database/commands/upgrade-version/0-30/0-30-migrate-email-fields-to-emails.command.ts @@ -305,14 +305,6 @@ export class MigrateEmailFieldsToEmailsCommand extends ActiveWorkspacesCommandRu ) { this.logger.log(`Migrating person email field of type EMAIL to EMAILS`); - await this.migrateDataWithinTable({ - sourceColumnName: 'email', - targetColumnName: 'emailsPrimaryEmail', - tableName: 'person', - workspaceQueryRunner, - dataSourceMetadata, - }); - const personEmailFieldMetadata = await this.fieldMetadataRepository.findOne( { where: { @@ -322,6 +314,22 @@ export class MigrateEmailFieldsToEmailsCommand extends ActiveWorkspacesCommandRu }, ); + if (!personEmailFieldMetadata) { + this.logger.log( + `Could not find person email field with standardId ${PERSON_STANDARD_FIELD_IDS.email}, skipping migration`, + ); + + return; + } + + await this.migrateDataWithinTable({ + sourceColumnName: 'email', + targetColumnName: 'emailsPrimaryEmail', + tableName: 'person', + workspaceQueryRunner, + dataSourceMetadata, + }); + if (personEmailFieldMetadata) { await this.fieldMetadataService.deleteOneField( {