Using Magento >= 1.6 data install scripts

As of Magento version 1.6, you can split the database structure and the data insertion with the new data setup scripts. The data scripts will work about the same way as your sql install scripts and have the same versioning conventions like the normal ones you are used to.

I sure hope you switched to the resource scripts as the mysql4 ones are deprecated (you can still use them, but as the fellow Magento developers decided to put one more layer of abstraction so magento can work on other database systems than only mysql, the prefix ‘mysql4’ isn’t the proper naming anymore).

Just to mention, you can do the same things in your normal sql install/upgrade scripts, but if you have for example a upgrade of your module with only data insertion, or just want to split the data from the structure, this one will for sure suit your needs. Oh, one more thing: you can use them right away if you have already configured your module for setup resources, the only thing you need to do is to create the data/{modulename}_setup folder like you created the sql one.

The data scripts reside in the data/{modulename}_setup like the normal scripts reside in the sql/{modulename}_setup. The naming convention of the files has a slight difference than your sql scripts: they have a prefix named ‘data’. For example, you would name a sql install script ‘install-1.0.php’ whereas the data install script would be named ‘data-install-1.0.php’. The same naming convention applies to the data upgrade scripts, so they are named for example ‘data-upgrade-1.0.1-1.0.2.php’.

On every version of your magento module, you can have one sql upgrade script, or one data script, or both. If both, then the data upgrade script will be called right after your sql upgrade script. If you have only the data script, it will execute it, then increment the version like it would do it with the sql ones. (for example if you create a data-upgrade-1.0.1-1.0.2.php script magento will increment the module version to 1.0.2. If you would decide afterwards to create a sql script, the name would be upgrade-1.0.2-1.0.3.php to increment to version 1.0.3).

For the more visual ones, here’s a example of the data and sql folders in a module of mine. As you can see, the data-upgrade increments from version to without the sql upgrade script, and as I didn’t need the data scripts after the v., I just continued with only sql scripts.

You made it all the way down here so you must have enjoyed this post! You may also like:

How I learned to stop worrying and love 3rd party modules for Magento Luka Rajcevic
, | 2

How I learned to stop worrying and love 3rd party modules for Magento

Changing default category sort direction in Magento Marin Grizelj
Marin Grizelj, | 1

Changing default category sort direction in Magento

Per product meta robots tag control in Magento Marko Martinovic
Marko Martinovic, | 19

Per product meta robots tag control in Magento


  1. Thank you for sharing this info. Is it Creating a record in core_resource table in the database ?

  2. Too bad they added the data-install, but didn’t add an uninstall-x.x.x.x.php file (and downgrade- would be even better), but I guess we have to wait for Magento 2 for that.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.