Magento 2 Data Migration Tool

Magento 2  comes with a brand new architecture and database design. To ease up upgrade process, Magento has now made their plans for this process clearer with the release of a Magento 2 Data Migration Tool that will help to transfer your database from older versions to the latest Magento 2 in some simple steps.The data migration may be troublesome for new users, but no worries I am sure this blog post would be of help for you !

How to install the Data Migration Tool

Magento 2 Data Migration Tool

You can install it from either packages.magento.com or from a GitHub repository.
Everything is fairly well documented : Install the Data Migration Tool

There are 3 main commands/steps for the migration: settings, data and delta. This and their sub-steps can be seen in config.xml.

cd vendor/magento/data-migration-tool/bin/
php migrate –help
 
Usage:
migrate –config=path/to/config.xml [options]
migrate –help
 
Possible modes:
settings Migrate system configuration
data Main migration of data
delta Migrate the data is added into Magento after the main migration
 
Available options:
–reset Reset the current position of migration to start from the beginning
–config Path to main configuration file, i.e.: etc/m1_version/config.xml
–verbose Verbosity levels: DEBUG, INFO, ERROR
–help Help information

Migrate Settings

You should migrate settings first. This mode migrates stores; websites; and different system configuration like shipping, payment, some tax settings etc.

Migrating data

When you migrate data, the Data Migration Tool verifies that tables and fields are consistent between Magento 1 and Magento 2. If not, an error displays that lists the problematic tables and fields. These entities, for example, can belong to some extensions from Magento 1 that do not exist in the Magento 2 database.

Migrate Delta

Now this is where it gets interesting. After successful data migration, you can always just append new M1 entries to M2 database with delta migration, it will continue where it stopped last time. Delta doesn’t migrate new or changed products or categories (at the moment of writing), only customers, orders, and similar customer related data.

While doing data migration, set of m2_* tables are created in your M1 database with set of triggers that enables tracking changes.

Delta is here to reduce migration time to minimum when going live with M2.

Migrate Media

Media files can simply be copy/pasted to appropriate places in M2 after products and categories are migrated, simple as that.

Customize Migration

Since there is no such thing as default Magento in the real world (XD), developers will always need to configure or customize this tool. The tool itself is flexible, since most of mapping is defined through xml files and filtered through php classes, Magento team really did good job here.

Let’s say we have custom varchar sales_flat_order.custom_column in M1. If we run data migration, we’ll end up with an error:

[ERROR]: Source fields not mapped. Document: sales_flat_order. Fields: custom_column

To ignore it we need to add following to map.xml file.

<source>
  <field_rules>
    <ignore>
      <field>sales_flat_order.custom_column</field>
    </ignore>
..

The only remark I have is that maybe unknown columns should be ignored by default. If there is column in M1 that isn’t defined in xml, the tool should ignore it, it would save lot of time.

Let’s say we want to move values to renamed custom_column and modify values in the process:

<source>
  <field_rules>
  ..
    <transform>
      <field>sales_flat_order.custom_column</field>
      <handler class="\Migration\Handler\AddPrefix">
        <param name="prefix" value="inchoo_"/>
      </handler>
    </transform>
    <move>
      <field>sales_flat_order.custom_column</field>
      <to>sales_order.new_custom_column</to>
    </move>
  ..

Example shows that Handler class can be used, or custom one created, for changing values on the fly during migration.

If mapping isn’t enough, whole new custom step can be created. Each step is composed out of Integrity, Data and Volume classes. Integrity is triggered before migration to check if everything is ok with mapping, Data transfers data, Volume checks if everything is ok after migration. Delta class can be added to support delta migrations.

We have finished this tutorial, and I hope it’s useful for you. See you again in our next Magento 2 tutorials.

Enjoy Magento 2 challenge with Magesolution’s tutorials and follow our earlier blog posts on Magento 2 structure and benefits.