How we fixed the perpetual hook_update_N merge conflict problem

Roomify, LLC · July 13, 2016

If you work on a Drupal site with a development team, you've probably run into merge conflicts created by database updates using the same update number. (E.g. developer 1 creates custom_module_update_7013 in one branch, and developer 2 creates the same update function in another branch) Wouldn't it be nicer if updates used machine names instead, or indeed almost anything besides incremented integers? After many weeks of wasting time fixing spurious conflicts and slowing down our development process on Roomify for Accommodations, we decided to do something about it.

We've created a new module called better_db_updates - it solves the problem by allowing modules to place database updates in individual files. The module also provides a drush command to run all updates, including better DB updates. Usage is really simple, just require the better_db_updates module and implement hook_better_updates_db_directory():

/**
 * Implements hook_better_db_updates_directory()
 */
function test_better_db_updates_directory() {
  return 'updates';
}

To add a database update that changes your site name, add a file called update_site_name.inc in the updates directory under your module's directory:

<?php

/**
 * Update to the new site name
 */

variable_set('site_name', 'My Drupal Site');
 

That's all there is to it! We hope you'll check out the module and offer feedback.

Twitter, Facebook