- If you have already cloned magento2 repository use
If you already have a pre-installed environment for you, navigate to the source git directory and execute
git remote add workshop [email protected]:fascinosum/magento2.git git fetch workshop
otherwise usegit fetch origin git checkout i2019 git pull origin i2019
git clone [email protected]:fascinosum/magento2.git
- Checkout to the
i2019branch - Uninstall Magento if it is installed
bin/magento setup:uninstall -q
- Update composer packages
composer install
- Install Magento 2.3.1 using
i2019branch. You can use any of the following methods:- WebSetup Wizard
- cli command
bin/magento setup:install --backend-frontname=admin --language=en_US \ --timezone=America/Los_Angeles --currency=USD --use-secure=0 --use-secure-admin=0 \ --use-rewrites=1 --admin-user=admin --admin-password=anyrand0mpass \ --admin-firstname=Admin --admin-lastname=Admin [email protected] \ --base-url=http://<domain_name>/ --base-url-secure=https://<domain_name>/ \ --db-user=<db_user> --db-password=<db_password> --db-name=<db_name>
- any installation script
- NOTE: to avoid additional complexity, do not use the database prefix
- Switch to the
i2019-modulebranch - Run
bin/magento setup:upgrade --convert-old-scripts 1
- Check the result in the
app/code/Blackbox/SmartModule/etc/db_schema.xmlfile - See
Setup\UpgradeSchema::addReplicaTableexecutes a direct SQL query.email_review_table_replicamust be manually declared inetc/db_schema.xml. Copy the declaration ofemail_review_tableand change only the attributenametoemail_review_table_replica - Remove
setup_versionattribute from themodulenode inapp/code/Blackbox/SmartModule/etc/module.xml - Run
bin/magento setup:upgrade --dry-run 1
- Check the result in
var/log/dry-run-installation.logfile. Expected result: the file does not exist or there are no changes for the module tables
-
Switch to the
i2019-dynamic-schema-changesbranchgit add . && git reset --hard HEAD && git checkout i2019-dynamic-schema-changes
-
Create a new schema patch with the name EnableAbandonedCartSegmentation using
bin/magento setup:db-declaration:generate-patch --type schema -- Blackbox_SmartModule EnableAbandonedCartSegmentation
command
- we use
--type schemaas command parameter for schema patches - NOTE: Patches should be named by their purpose.
- we use
-
Copy new changes from the
Setup/UpgradeSchema.phpfile to theSetup/Patch/Schema/EnableAbandonedCartSegmentation::applymethod (use code fromSetup/UpgradeSchema.php::enableAbandonedCartSegmentationmethod).Add
$setup = $this->moduleDataSetup; $setup->startSetup();
at the very beginning of the
Setup/Patch/Schema/EnableAbandonedCartSegmentation::applymethod and add$setup->endSetup();
at the end
-
Implement
\Magento\Framework\Setup\Patch\PatchVersionInterfacetoEnableAbandonedCartSegmentation. Use the appropriate module version value from theSetup/UpgradeSchema.phpas a return value for theSetup/Patch/Schema/EnableAbandonedCartSegmentation::getVersionmethod.- NOTE:
PatchVersionInterfaceis deprecated since it is used only for migration purposes. New patches that appear after module migration should not implement this interface. Migrated patches MUST implement this interface and return the version they are designated to in legacy setup script. This is required for backward compatibility.
- NOTE:
-
Run command
bin/magento setup:upgrade
- If you are faced with some difficulties you can switch to the
i2019-schema-patchesbranch and run the command again. To switch to the branch, rungit add . && git reset --hard HEAD && git checkout i2019-schema-patches
- If you are faced with some difficulties you can switch to the
-
Check the result in the database. There should the following tables:
abandoned_cart_table_index_store_1abandoned_cart_table_index_store_1_tmp
-
patch_listtable should contains row with the patch nameBlackbox\SmartModule\Setup\Patch\Schema\EnableAbandonedCartSegmentation -
Try to put any executable code, for example,
$this->moduleDataSetup->getConnection()->dropTable('abandoned_cart_table_index_store_1');
into the patch file and run
bin/magento setup:upgrade
one more time. Verify that
abandoned_cart_table_index_store_1still exists -
NOTE: After all setup code is migrated to patches the legacy schema setup/upgrade scripts can be deleted.
-
Switch to the branch
i2019-data-changesgit add . && git reset --hard HEAD && git checkout i2019-data-changes
-
Create a new data patch with the name PrepareInitialConfig using
bin/magento setup:db-declaration:generate-patch --type data -- Blackbox_SmartModule PrepareInitialConfig
command
-
Copy data changes from the
Setup/InstallData::prepareInitialConfigmethod to theSetup/Patch/Schema/PrepareInitialConfig::applymethod -
Copy all arguments from the
Setup\InstallData::__constructmethod to theSetup\Patch\Data\PrepareInitialConfig::__constructmethod, as well as all private properties of the class. -
Create AddSmartModuleUserCustomerAttribute and ConvertReviewMessageToJson data patches in the same way and copy data changes from the appropriate methods of the
Setup/UpgradeData.phpfile -
Implement
\Magento\Framework\Setup\Patch\PatchVersionInterfacefor all data patches. Use the appropriate module versions from theSetup/UpgradeSchema.phpas a return value forgetVersionmethod.- Use 2.0.0 as a module version for
PrepareInitialConfigpatch
- Use 2.0.0 as a module version for
-
Declare correct order for patches using
getDependenciesmethod.- Use
PrepareInitialConfig::classas dependency forAddSmartModuleUserCustomerAttributepatch - Use
AddSmartModuleUserCustomerAttribute::classsas dependency forConvertReviewMessageToJsonpatch
- Use
-
Run
bin/magento setup:upgrade
- If you are faced with some difficulties you can switch to the
i2019-data-patchesbranch and run the command again. To switch to the branch, rungit add . && git reset --hard HEAD && git checkout i2019-data-patches
- If you are faced with some difficulties you can switch to the
-
Check the
patch_listtable, it should contain rows with the following patch data names- Blackbox\SmartModule\Setup\Patch\Data\PrepareInitialConfig
- Blackbox\SmartModule\Setup\Patch\Data\AddSmartModuleUserCustomerAttribute
- Blackbox\SmartModule\Setup\Patch\Data\ConvertReviewMessageToJson
-
Check the
flagtable, there should be 2 new flags with the correct order of Blackbox_SmartModule versions- blackbox_flag_v_2_0_10
- blackbox_flag_v_2_1_3
-
NOTE: Since this is a migration scenario patches do not hold dependencies and the order is recognized by version, however new patches order is recognized by dependencies. Patches may have several dependencies, the final structure is a tree that is applied recursively. If you see that your patch requires some data from another patch you MUST add the dependency by refering the class name of the patch that your new one depends on.
- You can use you the existing state of the project or switch to the
i2019-data-patchesbranch - Use
command to generate
bin/magento setup:db-declaration:generate-whitelist --module-name Blackbox_SmartModule
etc/db_schema_whitelist.json. This file must contain all the entities from theetc/db_schema.xmlfile - Remove
<column name="quote_id"/>fromin<index referenceId="ABANDONED_CART_TABLE_INDEX_QUOTE_ID_STORE_ID_CUSTOMER_ID" indexType="btree"> <column name="quote_id"/> <column name="store_id"/> <column name="customer_id"/> </index>
db_schema.xml - Execute
one more time
bin/magento setup:db-declaration:generate-whitelist --module-name Blackbox_SmartModule
- Check
etc/db_schema_whitelist.json, there should be 2 indexer names"index": { "ABANDONED_CART_TABLE_INDEX_QUOTE_ID_STORE_ID_CUSTOMER_ID": true, "ABANDONED_CART_TABLE_INDEX_STORE_ID_CUSTOMER_ID": true }