Fix email migration (#7298)

Checks if person standard email field exists before running the
migration.
This commit is contained in:
Raphaël Bosi 2024-09-27 17:20:15 +02:00 committed by GitHub
parent e28d8dd952
commit 942281f4b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -305,14 +305,6 @@ export class MigrateEmailFieldsToEmailsCommand extends ActiveWorkspacesCommandRu
) { ) {
this.logger.log(`Migrating person email field of type EMAIL to EMAILS`); 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( const personEmailFieldMetadata = await this.fieldMetadataRepository.findOne(
{ {
where: { 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) { if (personEmailFieldMetadata) {
await this.fieldMetadataService.deleteOneField( await this.fieldMetadataService.deleteOneField(
{ {