Drupal update functions inside install file

The .install file of a Drupal module contains many update functions. What these update functions do ? The names of these functions follow the format <module_name>_update_N. The details on this format can be found here hook_update_N.  These update functions gets executed when we run “update.php”. This tutorial explains when and how these update functions get's invoked.






Let’s say a module has defined the  set of update functions given above. What does this mean ? does all these functions get’s executed when we run “update.php” ? Answer is No, it depends upon current module’s version and the latest update number that has already been processed as part of module’s installation.  An  example is given below.

Let’s say the module's  version is  "7.x-1.2" and  the original install file implements the following function. Now when you enable this module for the first time , an entry is created for this module in the drupal’s  “system” table with the schema_version  set to “7100”.

function <module_name>_update_7100() {


 …. Some code for updating database ...




Now if  you want provide an update in the next release ,  you can simply add an update function with the different update number(let’s say 7101) to the install file.

function <module_name>_update_7101() {


 …. Code related to your  update..




For this update to take effect, you need to run “update.php” after replacing the older *.install file with new *.install file. Once the update is successful the “schema_vrsion” in the table “system” automatically gets updated to new update number(7101).