- 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 git@github.com:fascinosum/magento2.git git fetch workshop
otherwise usegit fetch origin git checkout i2019 git pull origin i2019
git clone git@github.com:fascinosum/magento2.git
- Checkout to the
i2019
branch - Uninstall Magento if it is installed
bin/magento setup:uninstall -q
- Update composer packages
composer install
- Install Magento 2.3.1 using
i2019
branch. 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 --admin-email=test@example.com \ --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-module
branch - Run
bin/magento setup:upgrade --convert-old-scripts 1
- Check the result in the
app/code/Blackbox/SmartModule/etc/db_schema.xml
file - See
Setup\UpgradeSchema::addReplicaTable
executes a direct SQL query.email_review_table_replica
must be manually declared inetc/db_schema.xml
. Copy the declaration ofemail_review_table
and change only the attributename
toemail_review_table_replica
- Remove
setup_version
attribute from themodule
node inapp/code/Blackbox/SmartModule/etc/module.xml
- Run
bin/magento setup:upgrade --dry-run 1
- Check the result in
var/log/dry-run-installation.log
file. Expected result: the file does not exist or there are no changes for the module tables
-
Switch to the
i2019-dynamic-schema-changes
branchgit 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 schema
as command parameter for schema patches - NOTE: Patches should be named by their purpose.
- we use
-
Copy new changes from the
Setup/UpgradeSchema.php
file to theSetup/Patch/Schema/EnableAbandonedCartSegmentation::apply
method (use code fromSetup/UpgradeSchema.php::enableAbandonedCartSegmentation
method).Add
$setup = $this->moduleDataSetup; $setup->startSetup();
at the very beginning of the
Setup/Patch/Schema/EnableAbandonedCartSegmentation::apply
method and add$setup->endSetup();
at the end
-
Implement
\Magento\Framework\Setup\Patch\PatchVersionInterface
toEnableAbandonedCartSegmentation
. Use the appropriate module version value from theSetup/UpgradeSchema.php
as a return value for theSetup/Patch/Schema/EnableAbandonedCartSegmentation::getVersion
method.- NOTE:
PatchVersionInterface
is 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-patches
branch 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_1
abandoned_cart_table_index_store_1_tmp
-
patch_list
table 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_1
still 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-changes
git 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::prepareInitialConfig
method to theSetup/Patch/Schema/PrepareInitialConfig::apply
method -
Copy all arguments from the
Setup\InstallData::__construct
method to theSetup\Patch\Data\PrepareInitialConfig::__construct
method, 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.php
file -
Implement
\Magento\Framework\Setup\Patch\PatchVersionInterface
for all data patches. Use the appropriate module versions from theSetup/UpgradeSchema.php
as a return value forgetVersion
method.- Use 2.0.0 as a module version for
PrepareInitialConfig
patch
- Use 2.0.0 as a module version for
-
Declare correct order for patches using
getDependencies
method.- Use
PrepareInitialConfig::class
as dependency forAddSmartModuleUserCustomerAttribute
patch - Use
AddSmartModuleUserCustomerAttribute::classs
as dependency forConvertReviewMessageToJson
patch
- Use
-
Run
bin/magento setup:upgrade
- If you are faced with some difficulties you can switch to the
i2019-data-patches
branch 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_list
table, 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
flag
table, 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-patches
branch - 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.xml
file - 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 }