Magento: Upgrading mysql setup of a module

Suppose, you have a module called MyModule. Its version is 0.1.0. Now, you want to do some database changes for the module. You have the mysql setup file (mysql install file) mysql4-install-0.1.0.php in MyModule/sql/mymodule_setup folder of your module.

You don’t need to make direct changes to database. You can upgrade your module to make your necessary database changes. To do so,

1) You need to create a new mysql upgrade file inside MyModule/sql/mymodule_setup folder.

Let us suppose that you are going to change the version of your module from 0.1.0 to 0.1.1.

The mysql upgrade file name should be mysql4-upgrade-0.1.0-0.1.1.php

The upgrade format is like mysql4-upgrade-CURRENT_VERSION-UPGRADED_VERSION.php

2) Write necessary sql statements in the newly added mysql upgrade file.

3) You have to change the version in MyModule/etc/config.xml as well.

Change the version like 0.1.1. 0.1.1 is the new version for our module.

4) Reload your site. And you are done!