2

In Magento 1, you updated a database schema (add a table, column, etc.) by creating an upgrade_v[Previous]_v[Current].php file, change the version number in the config.xml, and Magento would look in the php file and run the upgrade. This was triggered on a page view in all environments.

With Magento 2, it's unclear to me how this is designed to work: Are you supposed to update the etc/module.xml with the new setup_version number, and then within the the UpgradeSchema.php file, target the specific version number within the upgrade() method with the code to update the schema, and then manually run bin/magento setup:upgrade?

Currently when I change the setup_version number in a module locally, as soon as I hit the home page Magento throws an error (you must run bin/magento setup:upgrade), then once I've run the the setup:upgrade the homepage again errors out on a permissions issue. Once I've run chmod -R 777 on the root directory, I again get the setup:upgrade error, and after running it again I can finally view the homepage without error.

What is the best practice to update a database schema in a Magento 2 production environment? Do you need to (manually) run setup:upgrade with a deployment script?

0

1 Answer 1

1

You described everything correctly. What could go wrong is that you ran setup:upgrade from a user that blocks permissions to the created/updated files for the web-server. It is recommended to have console user in the same group, as web user or in any other way ensure that files modified by that user don't break permissions for the web user.

1
  • Thanks BuskaMuza - that helps but only partially answers the question - is there no built in way to automate the setup:upgrade run? That seems problematic
    – dbcn
    Jan 25, 2016 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.