Magento Install and Upgrade Data Scripts Explained

Originally published at: http://www.sitepoint.com/magento-install-upgrade-data-scripts-explained/

While developing custom modules in Magento, I often have to deal with install and upgrade script issues. Normally, these issues arise because of mistakes in the naming convention, improper version numbers, or incorrect syntax. In this post, we’ll focus specifically on how to write infallible Magento install and upgrade scripts.

magento-ecommerce-square-logo

A Magento install and upgrade script is a part of module development, thus it’s recommended that you have some basic understanding of module development prior to reading this article.

Whenever you install or create any new module that contains database interaction, you will find an install and upgrade script in that module’s code directory that will run once you hit the URL. Magento’s core modules also follow the same install and upgrade structure. If you want to see some examples, open app/code/core/Mage/Catalog/sql/ catalog_setup. Here, you will find several install and upgrade scripts with proper naming conventions along with their version numbers.

Continue reading this article on SitePoint

Hi Chirag,

Since Magento 1.6.x, we have good changes in Resources mainly to support others databases.
The mysql4 classes are deprecated and the Magento only keep it up to backwards compatibility.

To show a little example, i caught part of config.xml from Mage/Customer:

    <customer_resource>
        <class>Mage_Customer_Model_Resource</class>
        <deprecatedNode>customer_mysql4</deprecatedNode>
            <entities>
                <entity>
                    <table>customer_entity</table>
                </entity>
                <address_entity>
                    <table>customer_address_entity</table>
                </address_entity>
             </entities>
            <!-- .... -->
    </customer_resource>

Another point that few people use or remember is that the Magento has a directory to install the module data called "data" and this has the same “sql” directory scheme.

We can see practical examples studying the Magento Core modules.

Sorry the long comment and congratulations :smiley:

@xiris thanks for chiming in, always good to have someone who’s in on it take a look at a post!

@xiris Thanks for pointing out. Though mysql4 classes are deprecated, using mysql4 classes should not create issues as its backwards compatible and i have seen many of pro Magento Extensions which are using same mysql4 classes. More about Cross-DB compatibility mentioned in this PDF

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.