Problem/Motivation

In the discussion of #2997960: Missing taxonomy hierarchy items in 8.6.0 after running taxonomy_update_8502, it seems that some site maintainers applied the update function after updating to Drupal 8.6.0, then applied it again when 8.6.1 was released. The first update added a table, and the second update threw an exception when it tried to create a table that was already there.

One suggestion was to add a truncate to the update function. This would solve the immediate problem for some users, allowing the update function to complete.

@plach noted that adding the truncate could hide other problems and that the best practice is to start from a database that has not had any failed update attempts.

Proposed resolution

If an update function creates a database table, then it should fail gracefully, with a useful error message, if that table already exists.

Add a helper function so that update functions can do this consistently and conveniently.

Remaining tasks

User interface changes

This will add a warning message, presented to users during updates when update functions attempt to create tables that already exist.

API changes

Add a new helper function available to update functions.

Data model changes

None

Comments

benjifisher created an issue. See original summary.

benjifisher’s picture

An update function can create a table directly, using db_create_table() or Drupal\Core\Database\Schema::createTable(), or it might create a table indirectly. For example, taxonomy_update_8501() uses updateFieldStorageDefinition() to create a new field on the taxonomy_term entity, which creates a new table.

I am not sure what the best way to do this is. Perhaps the update function should have an explicit try, and call the proposed helper function from the catch clause.

catch’s picture

#2 seems like a good plan to start with.

plach’s picture

My original idea was to add an helper class with static methods. Here we would add a method to check whether a table already exists. If this were the case, the method would display an useful error message suggesting to remove or maybe just rename (for good measure) the table and run the update again. It would also throw an exception to ensure the current update is not marked as applied.

The update function would just have to call the helper method at the beginning of the execution.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.