Working with setup scripts

Every time a module is installed via a php bin/magento module:enable command, Magento shows the following message: To make sure that the enabled modules are properly registered, run 'setup:upgrade'. The php bin/magento setup:upgrade command upgrades the Magento application, database data, and schema. Once triggered, the upgrade command instantiates MagentoSetupModelInstaller, which then goes through a series of methods. Its getSchemaDataHandler method reveals the types of available setup scripts:

  • InstallSchema.php
  • UpgradeSchema.php
  • Recurring.php
  • InstallData.php
  • UpgradeData.php
  • RecurringData.php

These scripts live under the <VendorName>/<ModuleName>/Setup directory.

Once successfully finished, the setup:upgrade command makes a new entry, or updates an existing one, in the setup_module table. There, we can see the schema_version and data_version values logged against each module.

When testing out setup scripts, we can manually delete and adjust our module entries under the setup_module table to trigger individual type of setup script. For example, we can leave schema_version as is, while changing the data_version.

Let's take a closer look at writing each of those scripts.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.234.83