Question

I recently downloaded some free extension for magento CE 1.7. When extracting the content of them I found they have a new folder as data inside the module. It has some scripts with the prefix data. At the same time the module has the sql directory and script files. If I want to add a new modification to the database where should I put my upgrade script? What is the version should defined in config.xml ? Any suggestions will be appreciated.

Was it helpful?

Solution

Magento uses two folders to separate the database installation structure, on sql you will put the table, attributes and column creation/modification, on data you will insert data to the DB.

They are declared at the same time as setup resources, so you can use them right after you put your setup resource on config.xml, these scripts follow the same naming conventions as sql scripts just adding the word 'data', for example data-install-1.0.php, data-upgrade-1.0.1-1.0.2.php, etc

more detailed info here: http://inchoo.net/ecommerce/magento/using-magento-1-6-data-install-scripts/

OTHER TIPS

The purpose of the sql directory is to put in here the scripts related with tables structures, alter tables, drop tables and so on. The data directory is set up to manage the "data" to fill up this tables. Like "insert into".

For example, i have "sql/mynamespace_mymodule/mysql4-install-0.1.0.php" to create a table "country_states", here i created the table structure, or better said, CREATE TABLE country states. And in another directory i have "data/mynamespace_mymodule/mysql4-upgrade-0.1.1.php", here i have the querys to fillup the table country states, like "INSERT INTO country_states".

The real purpose is maintain a better scripts/files organization.

Greetings.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top