AD0-E716 · Question #31
The developer is required to convert a modules database scripts from old install/upgrade setup files to a data patches format and does not want to apply database changes that were already done by…
The correct answer is A. Implement Patchversioninterface and return 1.5.4 on the getversion() method. According to the Develop data and schema patches guide for Magento 2 developers, data patches are classes that contain data modification instructions. They are defined in a <Vendor>/<Module_Name>/Setup/Patch/Data/<Patch_Name>.php file and implement…
Question
The developer is required to convert a modules database scripts from old install/upgrade setup files to a data patches format and does not want to apply database changes that were already done by install/upgrade scripts. The current module version is 1.5.4. What would be the recommended solution to skip changes that were already applied via old format (install/upgrade scripts)?
Options
- AImplement Patchversioninterface and return 1.5.4 on the getversion() method.
- BInside apply() method, check for module version and run the code if version is less than 1.5.4.
- CThis is not possible. A module cannot implement both data patch and install scripts.
How the community answered
(24 responses)- A83% (20)
- B4% (1)
- C13% (3)
Explanation
According to the Develop data and schema patches guide for Magento 2 developers, data patches are classes that contain data modification instructions. They are defined in a <Vendor>/<Module_Name>/Setup/Patch/Data/<Patch_Name>.php file and implement MagentoFrameworkSetupPatchDataPatchInterface. Data patches can also implement Patchversioninterface to specify the module version that the patch is associated with. The getVersion() method returns the module version as a string. To skip changes that were already applied via old format (install/upgrade scripts), the developer should implement Patchversioninterface and return 1.5.4 on the getVersion() method. This way, the data patch will only be applied if the module version is greater than or equal to 1.5.4. Verified Reference: https://devdocs.magento.com/guides/v2.3/extension-dev-guide/declarative-schema/data-
Topics
Community Discussion
No community discussion yet for this question.