Fix workspace relation sync (#11963)
## Context While deploying the IS_NEW_RELATION_ENABLED (we don't compute relation based on relationMetadata anymore) to existing workspace, I've tested to run a sync-metadata post feature flag activation. This has raised two issues: - the workspaceMigration generator (which is over-complex and should be refactored later) for fieldMetadata of type RELATION was not handling settings update properly ; - we need to delete existing fieldMetadata corresponding to the UUID foreignKey as they are not needed anymore. This is handled as a 0.53 upgrade command as 0.53 will also come with the full removal of the old relation system --------- Co-authored-by: Etienne <45695613+etiennejouan@users.noreply.github.com> Co-authored-by: prastoin <paul@twenty.com>
This commit is contained in:
+15
-11
@@ -221,8 +221,6 @@ export class WorkspaceMetadataUpdaterService {
|
||||
[];
|
||||
let updatedFieldRelationMetadataCollection: FieldMetadataUpdate<FieldMetadataType.RELATION>[] =
|
||||
[];
|
||||
let deletedFieldRelationMetadataCollection: FieldMetadataUpdate<FieldMetadataType.RELATION>[] =
|
||||
[];
|
||||
|
||||
/**
|
||||
* Create field relation metadata
|
||||
@@ -253,20 +251,26 @@ export class WorkspaceMetadataUpdaterService {
|
||||
}
|
||||
|
||||
if (!options || options.actions.includes('delete')) {
|
||||
deletedFieldRelationMetadataCollection = await this.updateEntities<
|
||||
FieldMetadataEntity<FieldMetadataType.RELATION>
|
||||
>(
|
||||
manager,
|
||||
FieldMetadataEntity,
|
||||
storage.fieldRelationMetadataDeleteCollection,
|
||||
['objectMetadataId', 'workspaceId'],
|
||||
);
|
||||
const fieldMetadataRepository =
|
||||
manager.getRepository(FieldMetadataEntity);
|
||||
|
||||
if (storage.fieldRelationMetadataDeleteCollection.length > 0) {
|
||||
await fieldMetadataRepository.delete(
|
||||
storage.fieldRelationMetadataDeleteCollection.map(
|
||||
(field) => field.id,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
createdFieldRelationMetadataCollection,
|
||||
updatedFieldRelationMetadataCollection,
|
||||
deletedFieldRelationMetadataCollection,
|
||||
deletedFieldRelationMetadataCollection:
|
||||
storage.fieldRelationMetadataDeleteCollection.map((field) => ({
|
||||
current: field,
|
||||
altered: field,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user