7

We are actively developing modules and when we push the changes to our production site, there are usually several configuration changes we need to make. Would be nice to automate this...thoughts?

Jonathan Day
  • 18,519
  • 10
  • 84
  • 137
Nick
  • 71
  • 3
  • Unless Magento has some very odd requirements when being deployed, I'd say this is a possible duplicate of [PHP Site Deployment Suggestion](http://stackoverflow.com/questions/2628835/php-site-deployment-suggestion). Basically, phing should help you. – Gordon Nov 17 '10 at 18:58

2 Answers2

8

Not sure if it is still actual, but if you mean changes to system -> config, then it is much more better to use such config.xml nodes instead of writing database upgrade.

Magneto processes core_config_data table into global XML structure, so you may just change XML structure without using db table for making changes to system configuration.

Here is small example:

<config>
   <stores>
       <french>
          <design>
             <theme>
                 <default>french</default>
             <theme>
          </design>
       </french>
   </stores>
   <websites>
       <base>
          <design>
             <theme>
                 <default>english</default>
             <theme>
          </design>
       </base>
   </websites>
</config>

In this example one configuration field is changed for two scopes in Magento. It is definition of current theme depending on current website and store.

So <stores /> node contains configuration values for a particular store. Where each child element is named with store code and contains configuration data in nested view. And <website /> node contains configuration values for a particular website. Where each child element is named with website code and contains configuration data in nested view as well.

Also there is available <default /> node for configuration values in global scope. But it will be overridden by <stores /> and <websites /> if a particular value is for a scope.

I am making changes to configuration only via config.xml because deploying the project is much easier when you just need to install it via Magento installer without doing changes in "System -> Config".

Ivan Chepurnyi
  • 9,233
  • 1
  • 43
  • 43
  • As far as I understand this technique can be used only for default values that don't exist or `NULL` at db table `core_config_data`. If value exists, we need to write database upgrade. Am I right? – Viacheslav Kondratiuk Jun 25 '12 at 13:21
  • @v.kondratyuk, yes you are right. Actually this approach let you specify default data set per store/website/default scope, that can be changed afterwards by admin user. It is always good to migrate configuration via XML file, if you exchange code between developers in the team, or qa deployments. If developer or some other user changed a value in DB, you shouldn't affect this change by db upgrade, because it may leed to debugging sessions for other devs in the team. – Ivan Chepurnyi Dec 08 '12 at 18:46
5

Make the changes as part of a an install or upgrade script in your module's "sql" directory. In your module's "config.xml" file increment the version number of every matching change and also remember to fill in the <config><global><resources><MODULE_setup><setup> node.

Because the script is run within the context of Magento you have access to all the normal functionality too, updates don't have to be in the form of SQL commands.

clockworkgeek
  • 37,650
  • 9
  • 89
  • 127
  • I agree with your comment, but would take it further i.e. "updates **SHOULD NOT** be in the form of SQL commands". I haven't come across any DDL or DML statments that cannot be executed via Magento's config structures. Much easier for version control. – Jonathan Day Nov 18 '10 at 02:15