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.

Command icon 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

jibran created an issue. See original summary.

chx’s picture

Status: Active » Postponed

This is not doable before #2766193: Add tests for multiple base fields is in.

chx’s picture

Issue summary: View changes
jibran’s picture

Status: Postponed » Active
rp7’s picture

Version: 8.x-2.x-dev » 4.x-dev

rp7’s picture

I 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.