Problem/Motivation
Right now, the module displays a summary of the pending changes just like on the Drupal status page, but this summary doesn't explain what about each field or entity has actually changed. This makes it difficult if this module is not able to automatically apply updates but you still need to know what the schema differences are so that you can fix them yourself. Is there any plan to extend this module to provide effectively like a field/entity schema diff to make this easier?
The motivation for this feature request is that a site we are maintaining has field and entity schema changes that resulted from having to carefully remove Multiversion several versions back (we removed it back when we were on Drupal 8 and are now running Drupal 9.3 and preparing for Drupal 10). With Multiversion removed, the site is running fine with the exception of the "Mismatched entity and/or field definitions" error on the status page, but we want to fix up this technical debt in case it causes problems in a future Drupal version. It looks like what's happened is that the database tables were updated to remove the extra fields that Multiversion was maintaining, but the entity schema in the key_value table still refers to the tables and fields that Multiversion added (e.g., comment_revision, comment_field_revision, etc.), resulting in the errors on the status page. Devel Entity Update can't fix this because the database tables are out-of-sync with the schema AND some of the updates that need to be done violate Drupal business rules regarding fields that already contain data.
Another use case for this is during development -- it would be great if a dev making changes to the schema could just run a command that lists what's changed between the active and last-installed entity/field schema, so they know what updates to write.
Having stepped through the code of this module, I understand how difficult Core makes it to get this level of data about the schema, since most of this functionality is handled by protected methods inside \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema, but it would still be great if there's a way to get precisely why the error about updates is appearing on the status page.
Proposed resolution
Implement a new command that can print a list of diffs for the changes that need to be applied to fields and entities (e.g., delete field X, make field Y revisionable, stop referencing table A in the field definition for field Z).
Comments
Comment #2
guypaddock commentedComment #3
guypaddock commentedComment #4
plachThis is a very reasonable request, but I think it would make more sense if core itself could provide a more detailed report or at least an API to generate one. As you were pointing out, at that point it would be easy for DEU to build a command around that. I'd support such a core feature request and would be happy to provide reviews until it gets merged.
Comment #5
mvonfrie commentedI really like to see this as well, no matter where it will be implemented. I currently have an issue with updating json_field from 1.0-RC4 to 1.0 or even 1.2, which is caused by the fix for #3252426. This module cannot update the fields automatically because they have contents. In this case that should not matter because the change is about the SqlLite data type and I'm not using SqlLite.
Comment #6
anybodyI agree this would be super helpful, even in core.
Core reports just say
but doesn't explain what exactly is mismatching and how to fix it.
AI says
should work, but in my case it always runs out of memory.
So having a
--showflag in this module or more details in core would be really great!Comment #7
anybodyJust found https://www.drupal.org/project/schema_diff which might help in the UI. Maybe it should be added to the module page?
Also see #3386947: Move into core to make the core status report messsage useful maybe you'd like to second this.