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 1.0.0.2 to 1.0.0.3 without the sql upgrade script, and as I didn’t need the data scripts after the v. 1.0.0.3, I just continued with only sql scripts.
6 comments
Is this applied for Enterprise edition as well?
when the script will be executed ?
What changes in config.xml?
Thank you for sharing this info. Is it Creating a record in core_resource table in the database ?
Too bad they added the data-install, but didn’t add an uninstall-x.x.x.x.php file (and downgrade-1.6.0.0-1.5.0.2 would be even better), but I guess we have to wait for Magento 2 for that.
Thank you for sharing this! This topic certainly lacks information on the Internet
I’d also recommend reading the document regarding database changes made in Magento 1.6 http://www.magentocommerce.com/images/uploads/RDBMS_Guide2.pdf