Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Revert a Drupal Database Update

Parent Feed: 

Sometimes, when testing an update hook to a Drupal module, you may need to revert it.

For example, you are setting some permissions for a certain role, you run the update but then realise there was another permission you should have enabled. Instead of adding another update hook, you can revert the update you just ran, amend your update hook, and then re-run the update.

Note*: this is only for reversible changes - like adding/removing permisisons; it will fail if the update had created a new field for example.

It's as simple as this SQL query:
update system set schema_version = XXXX-1 where name = 'module_name';

This means, you are telling your database to update the table 'system' using scheme_version 'XXXX-1' (this will be something like 7001 or 7137 or whatever N equals in your hook_update_N() function minus 1, so if the update was hook_update_7138 you would use 7137 where XXXX-1 is), and apply this update to 'machine name of the module'.

Note*: Do not try this unless you know what you are doing. Make sure you have a backup of your database in case things go wrong - of course you do, don't you?

*Note - notes were added from items left in the comments, to bring them to the body.

Filed Under:

  1. Drupal Planet
  2. Drupal Tutorials
  3. SQL
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web