cancel
Showing results for 
Search instead for 
Did you mean: 

Extension > Setup > Install/Update versioning

SOLVED

Extension > Setup > Install/Update versioning

I've have read the magento2 developer documentation and realized that versioning in UpdateData and UpdateSchema is only possible by using the version_compare in the middle of the upgrade method:

 

class \Magento\Cms\Setup\InstallData implements \Magento\Framework\Setup\UpgradeDataInterface
{
   public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
   {
        if (version_compare($context->getVersion(), '1.0.0', '<')) {
            ...
        }
   }
}

Please take a look at the version comparings in:

https://github.com/magento/magento2/blob/2.1.5/app/code/Magento/Catalog/Setup/UpgradeData.php

 

It's pretty messy and sensitiv to errors while declaring version dependencies programmatically.

I think that the way Magento 1 do is far better.

Just reminding myself about m1-sales-module, which include over 117 upgrade scripts:

app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.6.2-0.7.0.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.7.0-0.7.1.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.7.1-0.7.2.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.7.2-0.7.3.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.7.9-0.7.10.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.0-0.8.1.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.1-0.8.2.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.11-0.8.12.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.12-0.8.13.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.13-0.8.14.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.14-0.8.15.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.15-0.8.16.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.16-0.8.17.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.17-0.8.18.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.18-0.8.19.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.19-0.8.20.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.20-0.8.21.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.2-0.8.3.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.21-0.8.22.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.22-0.8.23.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.23-0.8.24.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.24-0.8.25.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.25-0.8.26.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.26-0.8.27.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.27-0.8.28.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.28-0.8.29.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.29-0.9.0.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.3-0.8.4.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.6-0.8.7.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.7-0.8.8.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.8.8-0.8.9.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.0-0.9.1.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.10-0.9.11.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.1-0.9.2.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.11-0.9.12.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.12-0.9.13.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.13-0.9.14.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.14-0.9.15.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.15-0.9.16.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.16-0.9.17.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.17-0.9.18.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.18-0.9.19.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.19-0.9.20.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.20-0.9.21.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.2-0.9.3.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.21-0.9.22.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.22-0.9.23.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.23-0.9.24.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.24-0.9.25.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.25-0.9.26.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.26-0.9.27.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.27-0.9.28.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.28-0.9.29.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.29-0.9.30.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.30-0.9.31.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.3-0.9.4.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.31-0.9.32.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.32-0.9.33.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.33-0.9.34.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.34-0.9.35.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.35-0.9.36.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.36-0.9.37.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.37-0.9.38.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.38-0.9.39.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.39-0.9.40.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.40-0.9.41.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.4-0.9.5.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.41-0.9.42.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.42-0.9.43.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.43-0.9.44.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.44-0.9.45.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.45-0.9.46.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.46-0.9.47.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.47-0.9.48.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.48-0.9.49.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.49-0.9.50.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.50-0.9.51.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.5-0.9.6.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.51-0.9.52.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.52-0.9.53.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.53-0.9.54.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.54-0.9.55.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.55-0.9.56.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.6-0.9.7.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.7-0.9.8.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.8-0.9.9.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-0.9.9-0.9.10.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.3.99-1.4.0.0.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.0-1.4.0.1.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.1-1.4.0.2.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.15-1.4.0.16.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.16-1.4.0.17.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.17-1.4.0.18.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.18-1.4.0.19.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.19-1.4.0.20.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.20-1.4.0.21.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.21-1.4.0.22.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.2-1.4.0.3.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.22-1.4.0.23.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.23-1.4.0.24.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.24-1.4.0.25.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.3-1.4.0.4.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.4-1.4.0.5.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.5-1.4.0.6.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.6-1.4.0.7.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.7-1.4.0.8.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.4.0.8-1.4.0.15.php
app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php
app/code/core/Mage/Sales/sql/sales_setup/upgrade-1.6.0.0-1.6.0.1.php
app/code/core/Mage/Sales/sql/sales_setup/upgrade-1.6.0.1-1.6.0.2.php
app/code/core/Mage/Sales/sql/sales_setup/upgrade-1.6.0.2-1.6.0.3.php
app/code/core/Mage/Sales/sql/sales_setup/upgrade-1.6.0.3-1.6.0.4.php
app/code/core/Mage/Sales/sql/sales_setup/upgrade-1.6.0.4-1.6.0.5.php
app/code/core/Mage/Sales/sql/sales_setup/upgrade-1.6.0.5-1.6.0.6.php
app/code/core/Mage/Sales/sql/sales_setup/upgrade-1.6.0.6-1.6.0.7.php
app/code/core/Mage/Sales/sql/sales_setup/upgrade-1.6.0.7-1.6.0.8.php
app/code/core/Mage/Sales/sql/sales_setup/upgrade-1.6.0.8-1.6.0.9.php

Now, imagine how the m2 Setup file would grow over time.

Currently, there are 7 version dependencies that are declared programmatically:

app/code/Magento/Sales/Setup/UpgradeSchema.php:29:        if (version_compare($context->getVersion(), '2.0.2', '<')) {
app/code/Magento/Sales/Setup/UpgradeSchema.php:68:        if (version_compare($context->getVersion(), '2.0.3', '<')) {
app/code/Magento/Sales/Setup/UpgradeSchema.php:72:        if (version_compare($context->getVersion(), '2.0.4', '<')) {
app/code/Magento/Sales/Setup/UpgradeSchema.php:87:        if (version_compare($context->getVersion(), '2.0.5', '<')) {
app/code/Magento/Sales/Setup/UpgradeData.php:68:        if (version_compare($context->getVersion(), '2.0.1', '<')) {
app/code/Magento/Sales/Setup/UpgradeData.php:71:        if (version_compare($context->getVersion(), '2.0.5', '<')) {
app/code/Magento/Sales/Setup/UpgradeData.php:75:        if (version_compare($context->getVersion(), '2.0.6', '<')) {

 

  1. Is it possible to to write the M2 upgrade scripts in the way of M1?
  2. What do you think about this confusing messy way writing version dependent upgrade scripts?
  3. What was the internal purpose of the Magento architects to redesign this approach? 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Extension > Setup > Install/Update versioning

> Is it possible to to write the M2 upgrade scripts in the way of M1?

 

Not with out of the box  systems, although it seems like it would be relatively straight forward to write a script that would glob up a director of upgrade scripts and use version_compare in a similar way.

 

What do you think about this confusing messy way writing version dependent upgrade scripts?

 

The best professional word to use is "weird" -- especially since Magento 1 had this problem solved, and other PHP frameworks have migration systems that work even better than that. 

 

What was the internal purpose of the Magento architects to redesign this approach? 

 

 

Speculating, but it probably comes down to team member's lack of experience building systems that folks outside their corporate hierarchies use.  It's a pattern you see a lot when a big corporation tries to get into open source development. 

View solution in original post

2 REPLIES 2

Re: Extension > Setup > Install/Update versioning

> Is it possible to to write the M2 upgrade scripts in the way of M1?

 

Not with out of the box  systems, although it seems like it would be relatively straight forward to write a script that would glob up a director of upgrade scripts and use version_compare in a similar way.

 

What do you think about this confusing messy way writing version dependent upgrade scripts?

 

The best professional word to use is "weird" -- especially since Magento 1 had this problem solved, and other PHP frameworks have migration systems that work even better than that. 

 

What was the internal purpose of the Magento architects to redesign this approach? 

 

 

Speculating, but it probably comes down to team member's lack of experience building systems that folks outside their corporate hierarchies use.  It's a pattern you see a lot when a big corporation tries to get into open source development. 

Re: Extension > Setup > Install/Update versioning

Also, worth mentioning: I've thrown together a M1 style setup script implementation for the UpgradeScema class -- installing via pestle.

 

http://alanstorm.com/magento-2-setup-migration-scripts/

 

Worth investigating if you miss your old scripts.