Get and Set Hook Update N Schema Version Number

Last modified: 
Sunday, March 29th, 2015

How to find a Drupal 7 module's [=hook_update_N()=] schema version number.

Print Module Information with Drush

drush pmi my_module

Example

$ drush @local pmi php
 Extension        :  php                                                
 Project          :  drupal                                             
 Type             :  module                                             
 Title            :  PHP filter                                         
 Description      :  Allows embedded PHP code/snippets to be evaluated. 
 Version          :  7.26                                               
 Date             :  2014-01-15                                         
 Package          :  Core                                               
 Core             :  7.x                                                
 PHP              :  5.2.4                                              
 Status           :  enabled                                            
 Path             :  modules/php                                        
 Schema version   :  module has no schema                               
 Files            :  php.test                                           
 Requires         :  none                                               
 Required by      :  none                                               
 Permissions      :  use PHP for settings                               
 Configure        :  None   

MySQL

select name,schema_version from system where name = 'my_module';

Example

mysql> SELECT name,schema_version FROM system WHERE name = 'my_module';
+-----------+----------------+
| name      | schema_version |
+-----------+----------------+
| my_module |           7026 |
+-----------+----------------+

Query via Drush

drush sqlq "select name,schema_version from system where name = 'my_module'"

Reset a Schema Version to 0

; Do it with SQL...
UPDATE system SET schema_version = 0 WHERE name = 'my_module' LIMIT 1;
# Or do it with drush...
drush ss my_module 0

You can rollback the schema_version to whatever number is meaningful in your usecase. Setting to 0 will cause all up hook_update_N() methods to execute on next updb.


The operator of this site makes no claims, promises, or guarantees of the accuracy, completeness, originality, uniqueness, or even general adequacy of the contents herein and expressly disclaims liability for errors and omissions in the contents of this website.