The Migrate Plus module also comes with some examples of how to build and manage migrations. Once you download the Migrate Plus module using drush dl migrate_plus, the examples are available in modules/contrib/migrate_plus/migrate_example.
The first step is creating a migration group, which is found in the config/install directory for the module for the Configuration Entity to be created when the module is installed. The migration group has basic attributes for a machine name, label, description, and source description:
id: beer
label: Beer Imports
description: A few simple beer-related imports, to demonstrate how to implement migrations.
source_type: Custom tables
shared_configuration:
key: default
Once you have the migration group defined, you would add individual migrations to it:
# Migration configuration for beer content.
id: beer_node
label: Beers of the world
migration_group: beer
source:
plugin: beer_node
destination:
plugin: entity:node
process:
type:
plugin: default_value
default_value: migrate_example_beer
title: name
nid: bid
uid:
plugin: migration
migration: beer_user
source: aid
sticky:
plugin: default_value
default_value: 0
field_migrate_example_country: countries
field_migrate_example_beer_style:
plugin: migration
migration: beer_term
source: terms
'body/value': body
'body/summary': excerpt
migration_dependencies:
required:
- beer_term
- beer_user
In the configuration definition, it defines the migration group that it is part of, the source migration plugin, the target entity that will be created or updated, and then how values from the source are mapped to it. For example, the field title in the node will be populated from the name attribute from the migration plugin. In addition to basic mappings, you can also add different plugins to process the result. These include:
- Callback: It triggers a callable with the value
- Concat: It concatenates an array of values
- DefaultValue: It sets a default value for missing values
- Explode: It converts a delimited string into an array of values
- Extract: It returns a single value from an array
- Flatten: It flattens a nested array to a single depth
- Get: It applies a regular expression to the value
- MachineName: It constructs a machine name from a value
- SkipOnEmpty: It skips the current field or row if the value is empty
- SkipRowIfNotSet: It skips the current row if the value is empty
- StaticMap: It maps the value to another value