Magento – install script and upgrade scripts for your extension
Do you want to add some custom tables or attributes for your custom Magento extension? Let’s understand the process with an extension named ”Insync_Test” to run our installation script.
I hope you are familiar with magento extension development, if not please read our previous blog
Let’s create the directory structure according to the following image.
Add registration file “Insync_Test.xml” in “app\etc\modules” to activate custom module.
Now, we make sure that Magento knows about the module
- Clear cache in Magento Admin, if cache is enabled.
- Go to System->Configuration
- Click Advanced
- In the “Disable modules output” setting box, look for your new module named “Insync_Test”
Now we will create configuration file “config.xml” in path “app\code\local\Insync\Test\etc\” for our module. Add below content.
188.8.131.52 Insync_Test Mage_Eav_Model_Entity_Setup <!— This class needed to create new attribute in Magento --> core_setup core_write core_read
Here version number is important as it decides latest script version to run.
Now we will create the script file with same version declared in “config.xml”.
Create “mysql4-install-184.108.40.206.php” in path “app\code\local\Insync\Test\sql\insync_test_setup\”
Make sure your script file version (in this case 220.127.116.11), should match version defined in “config.xml”.
Add below content to your script file
Now copy your extension into your Magento root folder.
Open Magento admin and clear cache.
If script ran successfully, you can find the table “insync_Test” in Magento Database.
Each time you clear Magento cache, Magento compares for Version number for “insync_test” listed in “core_resource” table and version number in “config.xml” file, if version mismatches Magento look for appropriate script file.
For up-gradation process, suppose if you want to add new functionality into your Magento Extension. You can create an upgrade file in the same folder where script file exists.
Let’s say you want to add a new customer attribute in Magento.
Create a new file “mysql4-upgrade-18.104.22.168-22.214.171.124.php” in “app\code\local\Insync\Test\sql\insync_test_setup”. This means extension will upgrade from 126.96.36.199 to 188.8.131.52. We need to change the version number in “config.xml” to 184.108.40.206, otherwise upgrade script will not run.
Add below content to upgrade file
And also if you check “core_resource” table in Magento Database. You will see latest version number for the extension. Upgrade file like this can be created as many times as required. Cheers, Now you can create install scripts for your extension.
Let me know after comment below if you have any problem.
You may also like it.