Understanding the flow of schema and data scripts

Simply put, the role of the schema scripts is to create a database structure supporting your module logic. For example, creating a table where our entities would persist their data. The role of the data scripts is to manage the data within existing tables, usually in the form of adding some sample data during module installation.

If we look a few steps back, we can notice how schema_version and data_version from the database match the setup_version number from our module.xml file. They all imply the same thing. If we were to now change the setup_version number in our module.xml file and run the php bin/magento setup:upgrade console command again, our database schema_version and data_version would ...

Get Magento 2 Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.