The existing SQL storage definition or Field items can now be changed. A flag, column_changes_handled, is used to allow changes to the database columns when \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::updateDedicatedTableSchema detects column changes. Previously, when database columns changes were detected an exception was thrown.
To use this feature set the flag just before the table schema is updated, say in an post_update hook.
Before
// Update the tracked entity table schema to the new storage definition.
\Drupal::service('entity.definition_update_manager')->updateFieldStorageDefinition($new_storage_definition);Resulted in a FieldStorageDefinitionUpdateForbiddenException, such as,
Failed: Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException: The SQL storage cannot change the schema for an existing field (changed in block_content entity) with data. in Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema->updateSharedTableSchema() (line 1843 of /var/www/html/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php)."
After
In a hook_update_N() or post update function
// Perform some schema changes to a field.
// Set flag to let EntityDefinitionUpdateManager know the column changes have been handled.
$new_storage_definition->setSetting('column_changes_handled', TRUE);
// Update the tracked entity table schema to the new storage definition.
\Drupal::service('entity.definition_update_manager')->updateFieldStorageDefinition($new_storage_definition);
Comments
Point out risks here?
Thanks for this very helpful feature!
If I get it right, the developer setting this flag is responsible for ensuring the schema change doesn't break things? => Which can happen with this flag and was the reason for the exception before, I think?
Perhaps that should be pointed out here emphasized?
Am I right?
Thank you :)
http://www.DROWL.de || Professionelle Drupal Lösungen aus Ostwestfalen-Lippe (OWL)
http://www.webks.de || webks: websolutions kept simple - Webbasierte Lösungen die einfach überzeugen!
http://www.drupal-theming.com || Individuelle Responsive Themes