Categories


Archives


Recent Posts


Categories


Magento 2: Setup/InstallSchema.php is Required. Sort of.

astorm

Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Updated for Magento 2! No Frills Magento Layout is the only Magento front end book you'll ever need. Get your copy today!

Although there’s no documentation stating this, based on system behavior it seems like the

Package/Module/Setup/InstallSchema.php

class files are sort of required by a Magento module.

I say sort of required because you can run a module without them. You can use that module to add features to Magento. However, a version number for that module will not be added to the setup_module table unless the InstallSchema class is present.

I discovered this when I tried adding an UpgradeSchema class to a module that didn’t have an InstallSchema. The UpgradeSchema still ran, but calling $context->getVersion()

public function upgrade(
    SchemaSetupInterface $setup, 
    ModuleContextInterface $context
)
{
    $setup->startSetup();

    $version = '[' . $context->getVersion() . ']';
    file_put_contents('/tmp/schema.log',$version . "n",FILE_APPEND);

    $setup->endSetup();
}

returned an empty string, as there were no entries for my module in the setup_module table.

Copyright © Alana Storm 1975 – 2023 All Rights Reserved

Originally Posted: 23rd February 2017

email hidden; JavaScript is required