I need to load an entity definition to add a constraint and test it, I found that this is possible with the following code:
$manager = \Drupal::entityDefinitionUpdateManager();
$entity_definition = $manager->getEntityType('node');
$entity_definition->addConstraint(‘name’);
But I wonder if this is the correct way or if exists another.
hook_update_N()
, one of the hooks that allows to alter an entity definition should be used.