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; so, we cannot exactly uninstall it on production just for triggering the schema creation again, not to mention losing the data. Luckily, there is a system in place for this, in the name of update hooks--hook_update_N()--where N represents the schema version. These are sequentially named hook implementations that go inside the module ...

Get Drupal 8 Module Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.