Skip to content

Instantly share code, notes, and snippets.

@schnippy
Last active October 24, 2018 19:51
Show Gist options
  • Save schnippy/767af6c39c11dae729316c69c24e3cf8 to your computer and use it in GitHub Desktop.
Save schnippy/767af6c39c11dae729316c69c24e3cf8 to your computer and use it in GitHub Desktop.
TIL: Checking module schema in database to confirm whether module updates have run

TIL: How to check module schema in database to confirm whether module updates have run

If I’m running database updates on a Drupal site and there is some question about whether or not the update fired, I can check this in the database itself from the command line.

Every module that has database updates will define these in their install file, ex. ctools.install and that file will have a number of install hooks that reference the schema number, ex:

/**
 * Revert the length of the ctools_object_cache.name column back to 128.
 */
function ctools_update_7003() {

When a module install hook successfully runs, the schema version for it is updated to this number in the database. In the above example, the ctools schema version for that update hook (the last one) is 7003, which should be the latest version.

In Drupal 7, I would check that against the systems table with a quick SQL query:

mysql> select name,schema_version from system where name="ctools";
+--------+----------------+
| name   | schema_version |
+--------+----------------+
| ctools |           7003 |
+--------+----------------+
1 row in set (0.01 sec)

In Drupal 8, this is done in the key_value table and the schema is separated out so the SQL query is simply:

select * from key_value where name="ctools" and collection='system.schema';
+---------------+--------+---------+
| collection    | name   | value   |
+---------------+--------+---------+
| system.schema | ctools | i:8000; |
+---------------+--------+---------+
1 row in set (0.01 sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment