6

I'm having trouble getting a custom module to install and update successfully. I'd like to examine the database for the modules update_N numbers. Is that possible? If it is, where do I look for it?

3 Answers 3

8

They're in key/value storage, which in the database would be the key_value table. Look for entries with a collection of system.schema, and a name matching the machine name of the module you're interested in.

Through the API, it's a bit easier:

$current_version = drupal_get_installed_schema_version('name_of_module');
5
  • Thanks, Clive - Perfect! One thing still puzzels me though; when I uninstall then install the module the version number is restored to the higest _N in the install file and the install hook is run but none of the update_N functions are executed. I'm guessing that maybe I could reset the version using the uninstall hook. Any thoughts on this? Thanks --- Mike
    – Mike
    Commented Feb 10, 2016 at 15:38
  • When you install a module, none of the hook_update_N() is invoked. Storing the higher update value is the right action Drupal does.
    – apaderno
    Commented Feb 10, 2016 at 17:08
  • Update hooks are not for when a module is installed. For that, there is hook_install(), which is executed every time a module is installed, as in Drupal 7.
    – apaderno
    Commented Feb 10, 2016 at 17:09
  • 1
    Yeah, what @kiamlaluno said. Think of hook_update_N as the way to get older versions of your module up-to-speed with the current codebase when it changes. For new installs, the current state of the module and any data it stores should be inline with what hook_update_N would have taken an older version to if it was upgraded
    – Clive
    Commented Feb 10, 2016 at 18:03
  • My instincts would have it different but as long as it's consistent that works too. Thanks for the insights.
    – Mike
    Commented Feb 10, 2016 at 19:02
2

There is another possibility as pointed in the documentation

You could use drush and run the following command:

drush php-eval "echo drupal_get_installed_schema_version('module_name');"

to find the last applied update hook for a specific module.

2

For Drupal 10 would be:

drush php-eval  "echo \Drupal::service('update.update_hook_registry')->getInstalledVersion('MODULE_NAME');"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.