Update hooks
At the beginning of this chapter, we defined two tables using hook_schema()
which got installed together with the module. To reiterate, if the module had already been installed, we could have triggered the schema installation using the drupal_install_schema()
function. However, what if we needed to add another column later on, say to the teams
table? Our module is installed, and so is the schema; we cannot exactly uninstall it on production just to trigger the schema creation again, not to mention losing the data. Luckily, there is a system in place for this, namely update hooks—hook_update_N()
—where N
represents the schema version. These are sequentially named hook implementations that go inside the module *.install
file and that are triggered when running the updates, either by going to /update.php
or by using the drush updated
command.
The main purpose of these update hooks is making schema alterations to existing database tables.
Note
If you...