Migration Generate Step-by-Step

We are going to work on a clean D8 site. So, issue something similar to:

1
drush dl drupal --drupal-project-rename=docroot && cd docroot && drush si -y standard

Enable Migrate required modules

We are going to use:

  • Migrate Upgrade
  • Migrate Plus
  • Migrate Tools

In the Drupal root, run: drush en -y migrate_upgrade

Edit settings.php to define a DB connection

After $databases['defaul']['default'] = [] array define the connections for migrate tasks:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
$databases['upgrade']['default'] = array (
  'database' => 'avcodb',
  'username' => 'lovelyUserName',
  'password' => 'impossiblePasswd',
  'prefix' => '',
  'host' => 'localhost',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);
// Pay special attention to the keys! (ie: 'acvod6') 
// This key needs to match the key defined in your migrate_plus.migration_group.migrate_drupal_6.yml file.
$databases['acvod6']['default'] = array (
  'database' => 'avcodb',
  'username' => 'lovelyUserName',
  'password' => 'impossiblePasswd',
  'prefix' => '',
  'host' => 'localhost',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);

Create a custom module to tweak migrations

Drupal Console is really useful for this

1
drupal gm

Remember to add migrate_upgrade as a dependency!

Generate a migration

Once D8 fresh site is installed, you defined the DB connection in settings.php, and migrate dependencies are in place, we can generate our migration.

drush migrate-upgrade --legacy-db-url='mysql://lovelyUserName:impossiblePasswd@localhost/avcodb' --legacy-root=/home/eu/git-mbm/acvo/docroot --configure-only

When this is done, we are going to add those migrate configs to our custom module, in order to tweak them as needed.

  1. Export migration to a tmp dir

drush config-export --destination=/tmp/migrate_configs

  1. Copy yaml migration configs into “orig” directory, so we can keep them unaltered in there in case we need them later.

    1
    cp /tmp/migrate_configs/migrate_plus.migration.* /tmp/migrate_configs/migrate_plus.migration_group.migrate_*.yml modules/custom/acvo_custom_migration/orig
    
    3. Finally copy yaml config files into our Custom Migration Module “config/install” directory. So we can remove the ones that we do not want, tweak them, etc…

1
rsync -avz modules/custom/acvo_custom_migration/orig/ modules/custom/acvo_custom_migration/config/install

So now, we will remove yaml file for those things we do not want to migrate, for example:

  • Node Revisions
  • Comments
  • System configs

Install fresh D8 (yes, once again)

1
drush si -y standard

Enable Required modules

You should enable all the D8 ported modules that you were using on your migrated site. For the modules that have no ports to D8, we are going to need some manual tweaking to be able to map the D6 module to the new D8 one.

Here is the table with modules that we need to enable in D8 (both Core, Contrib and my custom migration module)

Modules Table
PackageNameTypeVersion
Access controlContent Access (content_access)Module8.x-1.0-alpha1
Access controlMenu Per Role (menu_per_role)Module8.x-1.0-alpha1
AdministrationAdmin Toolbar (admin_toolbar)Module8.x-1.21
AdministrationAdmin Toolbar Extra Tools (admin_toolbar_tools)Module8.x-1.21
AdministrationAdminimal Admin Toolbar (adminimal_admin_toolbar)Module8.x-1.5
Chaos tool suiteChaos tools (ctools)Module8.x-3.0
CoreAutomated Cron (automated_cron)Module8.4.2
CoreBlock (block)Module8.4.2
CoreBreakpoint (breakpoint)Module8.4.2
CoreCKEditor (ckeditor)Module8.4.2
CoreColor (color)Module8.4.2
CoreComment (comment)Module8.4.2
CoreConfiguration Manager (config)Module8.4.2
CoreContact (contact)Module8.4.2
CoreContextual Links (contextual)Module8.4.2
CoreCustom Block (block_content)Module8.4.2
CoreCustom Menu Links (menu_link_content)Module8.4.2
CoreDatabase Logging (dblog)Module8.4.2
CoreField (field)Module8.4.2
CoreField UI (field_ui)Module8.4.2
CoreFilter (filter)Module8.4.2
CoreHelp (help)Module8.4.2
CoreHistory (history)Module8.4.2
CoreInternal Dynamic Page Cache (dynamic_page_cache)Module8.4.2
CoreInternal Page Cache (page_cache)Module8.4.2
CoreMenu UI (menu_ui)Module8.4.2
CoreNode (node)Module8.4.2
CorePath (path)Module8.4.2
CoreQuick Edit (quickedit)Module8.4.2
CoreRDF (rdf)Module8.4.2
CoreSearch (search)Module8.4.2
CoreShortcut (shortcut)Module8.4.2
CoreSystem (system)Module8.4.2
CoreTaxonomy (taxonomy)Module8.4.2
CoreText Editor (editor)Module8.4.2
CoreToolbar (toolbar)Module8.4.2
CoreTour (tour)Module8.4.2
CoreUpdate Manager (update)Module8.4.2
CoreUser (user)Module8.4.2
CoreViews (views)Module8.4.2
CoreViews UI (views_ui)Module8.4.2
Core (Experimental)Migrate (migrate)Module8.4.2
Core (Experimental)Migrate Drupal (migrate_drupal)Module8.4.2
Core (Experimental)Migrate Drupal UI (migrate_drupal_ui)Module8.4.2
Customacvo_custom_migration (acvo_custom_migration)Module
DevelopmentDevel (devel)Module8.x-1.2
DomainDomain (domain)Module8.4.2
DomainDomain Access (domain_access)Module8.4.2
DomainDomain Configuration (domain_config)Module8.4.2
DomainDomain Content (domain_content)Module8.4.2
Entity PrintEntity Print (entity_print)Module8.x-1.3
fieldField Permissions (field_permissions)Module8.x-1.0-beta4
Field typesAddress (address)Module8.x-1.3
Field typesDatetime (datetime)Module8.4.2
Field typesFile (file)Module8.4.2
Field typesImage (image)Module8.4.2
Field typesLink (link)Module8.4.2
Field typesMultiselect (multiselect)Module8.x-1.0
Field typesOptions (options)Module8.4.2
Field typesText (text)Module8.4.2
FieldsConditional Fields (conditional_fields)Module8.x-1.0-alpha4
FieldsField Group (field_group)Module8.x-3.0-beta1
FieldsSelect (or other) (select_or_other)Module8.x-1.0-alpha3
File metadataFile metadata - EXIF (file_mdm_exif)Module8.x-1.1
File metadataFile metadata manager (file_mdm)Module8.x-1.1
MediaImageMagick (imagemagick)Module8.x-2.2
MigrationDrupal Upgrade (migrate_upgrade)Module8.x-2.0-beta1
MigrationMigrate Plus (migrate_plus)Module8.x-4.0-beta2
MigrationMigrate Tools (migrate_tools)Module8.x-4.0-beta2
OtherBackup and Migrate (backup_migrate)Module8.x-4.0-beta3
OtherPathauto (pathauto)Module8.x-1.0
OtherToken (token)Module8.x-1.0
Performance and scalabilityFast 404 (fast404)Module
StatisticsGoogle Analytics Lite (google_analytics_lite)Module8.x-1.1
ViewsBetter Exposed Filters (better_exposed_filters)Module8.x-3.0-alpha3
ViewsViews Bulk Operations (views_bulk_operations)Module8.x-1.0
ViewsViews Data Export (views_data_export)Module8.x-1.0-alpha4
Views Bulk OperationsViews Bulk Edit (views_bulk_edit)Module8.x-2.0-beta1
Web servicesRESTful Web Services (rest)Module8.4.2
Web servicesSerialization (serialization)Module8.4.2
Web servicesSerialization (CSV) (csv_serialization)Module8.x-1.0
CoreBartik (bartik)Theme8.4.2
CoreSeven (seven)Theme8.4.2
OtherAdminimal (adminimal_theme)Theme8.x-1.3

In order to install and enable these, I have created two scripts in order to add composer dependencies and enabling drupal modules.

Backup D8 fresh install with required modules enabled

Just run a DB backup, so you can restore after generating the migration.

drush mysql-dump > ../db_bups/acvod8.local.clean_2017_12_21.sql

Check Migrate configs

Enable the custom migration module first!

drush en acvo_custom_migration -y

To make sure we are running our defined migrations config files (and any other tweak we did on our custom module) we run:

drush migrate-status

And we check if the selected yml files are in there as migrations.

At this point you could make a few different decisions

  • Manually create the CTs, add fields, etc in your fresh D8 site. And then, you will be able to use the custom module yml files, add Source, Process and Destination plugins, in order to map your fields and CTs before the migration.
  • Run each migration, cross your fingers ๐Ÿคž, and hope the migrations will just work out-of-the-box
  • Run all the migrations!! ๐Ÿ™€๐Ÿ™€๐Ÿ™€

So… things will probably break. We have to accept that fact, and start tweaking, fixing and debugging each migration.

A good approach is to start importing each content type migration, using the –execute-dependencies

drush migrate-import --execute-dependencies upgrade_d6_node_member_information

UPDATE 02/01/2018

  • Import Profile Pictures (D6 core profile module) and create file entities with it.
  • Being able to attach those file entities to user entities. Up to now, the Files have the UID, but the table user__field_profile_image is not populating the image fields… probably a missing some join?