- 🇺🇸United States amaria
I am still having a problem with this. After updating my field schema with a new column, and use code from #60/#66 in an update hook, it doesn't work.
When I get the columns from the table mapping...
$columns = $table_mapping->getColumnNames($field_name);
It does not contain the new property yet so it fails at this...
$field_exists = $schema->fieldExists($table_name, $columns[$property]);
Am I missing something before I run this code?
- 🇩🇪Germany Anybody Porta Westfalica
Once again ran into this, now in 🐛 SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'field_access_role_id' cannot be null Fixed . I'll ask @Grevil if he can help to push things forward here #74 + #79.
Could we get some core maintainer feedback on #80 and the implementation in general perhaps?
To ensure this goes into the right direction and is best practice? We shouldn't waste time, this is really essential to maintain field schema changes in contrib. - 🇺🇸United States apmsooner
Same as #88 for me. The code examples the patch work is based on don't work exactly right for me. Tested with drupal 10 php 8.1.
- For adding new column, I think this
$field_exists = $schema->fieldExists($table_name, $columns[$property]);
.... should be this:$field_exists = $schema->fieldExists($table_name, $property);
Otherwise it fails with php error... - This
$manager->updateFieldStorageDefinition($field_storage_definition);
wipes out tables with existing data so I scrapped it and did my own thing. Through trial an error I got something working in a branch of a very complex module scenario. I don't claim it to be perfect but its working. The key part i needed was restoring the existing data after modification which isn't documented well anywhere. https://git.drupalcode.org/project/custom_field/-/blob/updater_service/s...
Open to thoughts and suggestions on my approach. It is indeed more complex than I anticipated.
- For adding new column, I think this
- 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10
Hiding patches
Should we change this into a meta and split it into three separate issues in order of difficulty:
- Adding a new column with a default value (static value)
- Removing a column
- Updating a column
Both custom field and composite field have a concrete use case for this, particularly 1 and 2.
- 🇩🇪Germany Anybody Porta Westfalica
@larowlan: I'm unsure, because the functionality might be quite similar and I'm not sure, that would speed things up?
You decide! :)We've created https://www.drupal.org/project/devel_schema_change_helper → some weeks ago because we needed those helpers again and again. We could also prepare the functionality there and move it over into core once it's finished to have a working solution in contrib. What do you think?
I added the link to the issue summary!
Happy to see progress here, this is really really important for DX!