Repository: twentyhq/twenty
File: packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-runner/action-handlers/field/services/update-field-action-handler.service.ts (TypeScript)

Code before:
    const { entityId } = action;

    await fieldMetadataRepository.update(
      entityId,
      fromFlatEntityPropertiesUpdatesToPartialFlatEntity(action),
    );
  }

  async executeForWorkspaceSchema(
    context: WorkspaceMigrationActionRunnerArgs<UpdateFieldAction>,
  ): Promise<void> {
    const {
      action,
      queryRunner,
      allFlatEntityMaps: { flatObjectMetadataMaps, flatFieldMetadataMaps },
      workspaceId,
    } = context;
    const { entityId, updates } = action;

    const currentFlatFieldMetadata = findFlatEntityByIdInFlatEntityMapsOrThrow({
      flatEntityId: entityId,
      flatEntityMaps: flatFieldMetadataMaps,
    });

    const objectMetadataUniversalIdentifier =
      currentFlatFieldMetadata.__universal?.objectMetadataUniversalIdentifier;

    if (!objectMetadataUniversalIdentifier) {
      throw new WorkspaceMigrationActionExecutionException({
        message: `objectMetadataUniversalIdentifier is not defined for field metadata ${entityId}`,
        code: WorkspaceMigrationActionExecutionExceptionCode.NOT_SUPPORTED,
      });
    }

    const flatObjectMetadata = findFlatEntityByUniversalIdentifierOrThrow({
      flatEntityMaps: flatObjectMetadataMaps,
      universalIdentifier: objectMetadataUniversalIdentifier,
    });

    const { schemaName, tableName } = getWorkspaceSchemaContextForMigration({
      workspaceId,
      flatObjectMetadata,
    });

    let optimisticFlatFieldMetadata = structuredClone(currentFlatFieldMetadata);

    const defaultValueUpdate = findFlatEntityPropertyUpdate({
      flatEntityUpdates: updates,
      property: 'defaultValue',
    });
    const hasDefaultValueUpdate = isDefined(defaultValueUpdate);

Review comment (suggestion):
***Remark:*** Remark `__universal` is current marked as optional for incremental migration purpose
About to make it required in following PRs entity by entity

Code after:
    const { entityId } = action;

    await fieldMetadataRepository.update(
      entityId,
      fromFlatEntityPropertiesUpdatesToPartialFlatEntity(action),
    );
  }

  async executeForWorkspaceSchema(
    context: WorkspaceMigrationActionRunnerArgs<UpdateFieldAction>,
  ): Promise<void> {
    const {
      action,
      queryRunner,
      allFlatEntityMaps: { flatObjectMetadataMaps, flatFieldMetadataMaps },
      workspaceId,
    } = context;
    const { entityId, updates } = action;

    const currentFlatFieldMetadata = findFlatEntityByIdInFlatEntityMapsOrThrow({
      flatEntityId: entityId,
      flatEntityMaps: flatFieldMetadataMaps,
    });

    const objectMetadataUniversalIdentifier =
      currentFlatFieldMetadata.__universal?.objectMetadataUniversalIdentifier;

    if (!isDefined(objectMetadataUniversalIdentifier)) {
      throw new WorkspaceMigrationActionExecutionException({
        message: `objectMetadataUniversalIdentifier is not defined for field metadata ${entityId}`,
        code: WorkspaceMigrationActionExecutionExceptionCode.NOT_SUPPORTED,
      });
    }

    const flatObjectMetadata = findFlatEntityByUniversalIdentifierOrThrow({
      flatEntityMaps: flatObjectMetadataMaps,
      universalIdentifier: objectMetadataUniversalIdentifier,
    });

    const { schemaName, tableName } = getWorkspaceSchemaContextForMigration({
      workspaceId,
      flatObjectMetadata,
    });

    let optimisticFlatFieldMetadata = structuredClone(currentFlatFieldMetadata);

    const defaultValueUpdate = findFlatEntityPropertyUpdate({
      flatEntityUpdates: updates,
      property: 'defaultValue',
    });
    const hasDefaultValueUpdate = isDefined(defaultValueUpdate);