What is the use of Setup classes in Magento2:
Before see the magento2 setup classes first we will re-call magento1.x setup classes once.
Magento1.X:
In magento1.x if we need to create new table, then we will use Install script.
Ex:install-1.0.0.php
In case if we are going to upgrade our database table then we will use upgrade script.
Sample:
upgrade-1.0.0-1.0.1.php (using this script we are adding/removing some changes in our table)
upgrade-1.0.1-1.0.2.php (similarly again we are adding/removing some changes in our table)
This is process we are following in magento1.x . Consider if we upgrade our table minimum 20
time (20 changes) then yes atleast 10 to 20 upgrade file we have to run.
Magento2.x:
In Magento2.x it is simple.Here there will be only one class but yes we can use more than one
times .No more version setup files in Magento2.x.
InstallSchema :
InstallSchema is helping to create a new table in M2. Using install class we declare our table &
table columns values.
UpgradeSchema:
We can introduce new column filed into table or we can drop the column from the table using
upgradescheme.
InstallData:
InstallData will allow us to insert data into newly create table.
UpgradeData:
We can update the mysql table data with using model/resource model. This one will helpful to
get table row and update data value using upgrade method in upgradeData.php
Ex: getTableRow , updateTableRow
Recurring :
This class will helpful to do some think after what i specified. Using this method we can set some
activity after run this setup:upgrade or after run my second module. Some think like a observer
activity (not fully just for reference)
Uninstall:
This class is useful for removing modules and tables or columns & data from the database.
CORNER OF BLOG: