Magento Module Scripts – Upgrade Schema – Install&Upgrade Data – Part 03

Right after the Install Schema, we’ll learn about the Upgrade Schema. Later we’ll learn about the process of upgrading and installing data. So, here we’ll continue the article series of Magento 2 install script and this is the part 3 of the same topic.

However it’s quite boring to read such long tech articles and build a expert skill to accomplish this kind of tech jobs such as  installing Mage 2 scripts. On the other hand, you can just hire us for doing all tech stuff for your newly built website or for the reason of maintenance. Because we’re offering full web development & tech support 24×7 round the year with Magento cloud hosting plans. Absolutely free! Also enjoy discounts & coupons on monthly billing for different occasions. Buying a plan begins as low as $9.99 per month!

Tanzia Farin Chy for Aspiration hosting

Magento 2 Install Script – Upgrade Schema

Either the module is upgrading or installing for any another purpose. In both cases, the Setup\UpgradeSchema::upgrade() will execute generously. As we already knew that separate upgrade versions for different upgrade scripts are no more available. Instead of that all possible versions are need to be handled by UpgradeSchema class. So the scenario is quite different as mentioned in earlier articles.

namespace Aspiration\Custom\Setup;
 
use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
 
class UpgradeSchema implements UpgradeSchemaInterface
{
    public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $setup->startSetup();
 
        // all possible versions are need to be handled by UpgradeSchema class.
 
        if(!$context->getVersion()) {
            //this is no previous version found. So, the installation and InstallSchema executed
            //Note: As everything mentioned following is true for installation.
        }
 
        if (version_compare($context->getVersion(), '1.0.1') < 0) { //Use this code for upgrading to 1.0.1 } if (version_compare($context->getVersion(), '1.0.3') < 0) { // Use this code for upgrading to 1.0.3. } $setup->endSetup();
    }
} 

Magento 2 Install Script – Install & Upgrade data

Here, we have to insert the whole Data Setup Scripts carrying entries in our DB. As examples of data setup we can include Different default roles and groups, All CMS pages including 404 and the default Mage attributes etc.
Right after the Schema setup ends the data setup is executed. Here Note, interestingly both of them works in similar way.

Also check for the additional examples under following path in Mage module:

check/Setup/folder

Now reading Part 03 | Part 01 | Part 02