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 updated to this new version number.
This is done through module's install
and upgrade
scripts. If we take a quick look at the setup/src/Magento/Setup/Model/Installer.php
file, we can see a function, getSchemaDataHandler
, with content as follows...