Issue #3406172 by mandclu: Provide a flag to allow updates to stored schema for fields
parent
e0644f929b
commit
fdfb3c6675
|
@ -1746,7 +1746,7 @@ class SqlContentEntityStorageSchema implements DynamicallyFieldableEntityStorage
|
|||
}
|
||||
}
|
||||
else {
|
||||
if ($this->hasColumnChanges($storage_definition, $original)) {
|
||||
if (empty($storage_definition->getSetting('column_changes_handled')) && $this->hasColumnChanges($storage_definition, $original)) {
|
||||
throw new FieldStorageDefinitionUpdateForbiddenException('The SQL storage cannot change the schema for an existing field (' . $storage_definition->getName() . ' in ' . $storage_definition->getTargetEntityTypeId() . ' entity) with data.');
|
||||
}
|
||||
// There is data, so there are no column changes. Drop all the prior
|
||||
|
@ -1839,7 +1839,7 @@ class SqlContentEntityStorageSchema implements DynamicallyFieldableEntityStorage
|
|||
}
|
||||
}
|
||||
else {
|
||||
if ($this->hasColumnChanges($storage_definition, $original)) {
|
||||
if (empty($storage_definition->getSetting('column_changes_handled')) && $this->hasColumnChanges($storage_definition, $original)) {
|
||||
throw new FieldStorageDefinitionUpdateForbiddenException('The SQL storage cannot change the schema for an existing field (' . $storage_definition->getName() . ' in ' . $storage_definition->getTargetEntityTypeId() . ' entity) with data.');
|
||||
}
|
||||
|
||||
|
|
|
@ -112,4 +112,22 @@ class SqlContentEntityStorageSchemaColumnTest extends KernelTestBase {
|
|||
$entity_definition_update_manager->updateFieldStorageDefinition($field_storage_definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that schema changes are updated for fields with data with the flag.
|
||||
*/
|
||||
public function testColumnUpdateWithFlag() {
|
||||
// Change the field type in the stored schema.
|
||||
$schema = \Drupal::keyValue('entity.storage_schema.sql')->get('entity_test_rev.field_schema_data.test');
|
||||
$schema['entity_test_rev__test']['fields']['test_value']['type'] = 'varchar_ascii';
|
||||
\Drupal::keyValue('entity.storage_schema.sql')->set('entity_test_rev.field_schema_data.test', $schema);
|
||||
|
||||
// Now attempt to run automatic updates. It should succeed if the
|
||||
// column_changes_handled flag is passed.
|
||||
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
|
||||
$field_storage_definition = $entity_definition_update_manager->getFieldStorageDefinition('test', 'entity_test_rev');
|
||||
// Provide the flag to allow schema updates.
|
||||
$field_storage_definition->setSetting('column_changes_handled', TRUE);
|
||||
$entity_definition_update_manager->updateFieldStorageDefinition($field_storage_definition);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue