Upgrading a module
Imagine that we have a module in version 1.0.0 and that we want to change its version to 1.0.1. In the first version, we missed a column in a table, and we decided to add it in the new version. How can we do it without obliging our users to reset the module and lose the data? That’s what upgrades are for!
Let’s say that our initial table was the ps_testmodule_item
table and that we want to add a position
integer column to it in the new version.
First, we can add an upgrade/
folder to our module root folder. And let’s add a new upgrade/upgrade-1.0.1.php
file to it. It will contain the function that will be called on upgrading to the 1.0.1
version of the current module. There, we will be able to execute our table column changes.
On upgrading, the called function will be upgrade_module_1_0_1($module)
.
In our example, our upgrade/upgrade-1.0.1.php
file will contain the following code:
<?php function upgrade_module_1_0_1($module...