Writing Update Hooks

Articles

Get/Set Schema Versions

When writing hooks or investigating failed database updates it’s useful viewing and setting/resetting schema versions.

Command line via Drush

drush ev 'print \Drupal::keyValue("system.schema")->get("the_module") . "\n";'
drush ev "\Drupal::keyValue('system.schema')->set('the_module', (int) 8102)";

In code


// GET  
$ver = drupal_get_installed_schema_version('moduleName');
$ver = \Drupal::keyValue("system.schema")->get("moduleName");

//SET
drupal_set_installed_schema_version("moduleName", "8000");
\Drupal::keyValue('system.schema')->set('moduleName', (int) 8102);