Some people assume that in hook_update_N() anything can be executed. This is not true in reality, because hook_update_N() is used to repair a "broken Drupal" due to changes in code/yml files. A common usecase of hook_update_N() though was to just update some content, for which usecase Drupal needs to be 100% functional. This is not possible during hook_update_N().
Given that, a new feature was introduced which runs after all pending hook_update_N() implementations. At that point, Drupal is "repaired", fully bootstrapped, and the full extent of the API may be used.
Create a $module.post_update.php file and add a hook_post_update_NAME() function, with NAME being an arbitrary machine name.
/**
* Change the title of a specific node.
*/
function example_post_update_change_title_of_node() {
$node = \Drupal::entityManager()->loadEntityByUuid('FC0C01C6-B758-450D-A1BC-93D91D7786CB');
$node->setTitle('hello world');
$node->save();
return t('Node successfully updated.');
}
If you define multiple functions they are executed in the order they are defined in this file. Drupal also ensures to not execute the same hook_post_update_NAME() function twice. Unlike hook_update_N() this new hook does not support any dependency between each other.