M
M
Michael2016-11-16 21:40:44
PHP
Michael, 2016-11-16 21:40:44

How to update module data in magento 2?

I am writing magenta modules that have a data update script Setup/InstallData.php. Now it was necessary to add new data in an already existing module. Started working with Setup/UpgradeData.php.
For rolling updates, system developers like to use this technique:

if (version_compare($context->getVersion(), '2.0.6', '<')) {
    $this->upgradeVersionTwoZeroSix($customerSetup);
}

I understand that they rely on the version of the system and, if necessary, make changes. Also, each module has its own version:
<module name="Vendor_CustomerAttributes" setup_version="2.1.0" schema_version="0.1.1"></module>

Empirically, I realized that setup_version is the version of the system.
I would like to have my own version of the module and the ability to update the module regardless of the update of the system itself. Those. so that you can do composer update and setup:upgrade in production (or local) and, depending on the age of the module, code blocks will be executed that will update the data.
So, where can I find explanations for attributes in and how do I get the version of my module in code (like $context->getVersion())?
PS It turned out chaotically, but if something is not clear, then I will add it in other words.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
imdeveloper, 2016-11-20
@link_web

inchoo.net/magento-2/setup-scripts-magento-2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question