
So let's think on delete.
On MySQL / SQLite, not much needs to be done. When a dedicated table field gets dropped, the trigger is gone with it, no cleanup is necessary. When a shared table has two columns and one gets dropped then the trigger needs to be recreated but that's all, the same code can handle this. Changing the if (!$schema->fieldExists($table, $column_int)) {
to
$int_exists = $schema->fieldExists($table, $column_int);
if ($schema->fieldExists($table, $column) != $int_exists)) {
$changed[] = $column_int;
}
if (!$int_exists) {
$schema->addField($table, $column_int, $spec);
}
is enough here. However, we need the test for the multiple column case before this can happen.
On PgSQL, table drop equally drops the trigger vs a column drop needs the relevant trigger dropped. The relevant function always needs to be dropped, though.
And this is not optional, if you drop a column in a shared table then the triggers will break the DB. However, that's insanely rare so I am not worried. This will be done in a few days.
Issue fork dynamic_entity_reference-2766189
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
chx CreditAttribution: chx as a volunteer commentedThis is not doable before #2766193: Add tests for multiple base fields is in.
Comment #3
chx CreditAttribution: chx as a volunteer commentedComment #4
jibran#2766193: Add tests for multiple base fields and #2771737: Update does not work for base fields are done so we can work on this now.
Comment #5
rp7 CreditAttribution: rp7 for Government of Flanders commentedComment #7
rp7 CreditAttribution: rp7 for Government of Flanders commentedI found out about this issue because I'm trying to update the Linkchecker module we're using on a project. They decided to move away from using the Dynamic Entity Reference module for one of their entity's base fields (#3375553: Remove Dynamic Entity Reference (DER) dependency).
When doing the upgrade, I started noticing fatal errors when saving Linkchecker entities because something was trying to write to the target_id_int column, while that column no longer existed. Appeared that the DER triggers we're still in place. These were not removed, although the DER field was removed. I created an initial MR that removes triggers when a DER field is removed from a shared table.
Insights are welcome if this is the right approach.