D10 Migrations - pierregermain/MyDrupal GitHub Wiki
31 Days of Drupal Migrations
https://agaric.coop/31-days-drupal-migrations
Day 1 Understanding the ETL process
-
A migration is a Extract, transform, and load (ETL) procedure.
-
In Drupal, each step is performed by a Migrate plugin:
- The extract step is provided by source plugins
- The transform step is provided by process plugins. Nice to use: Migrate Plus
- The load step is provided by destination plugins
Drupal migrations: A 2 step process
- Migration on Drupal is a 2 step process: Write your migration and then execute it!
- You can only use one source and one destination for each migration file.
- It is important to only write one migration file per entity bundle (i.e one CT per node).
- Usually we will run the migration using drush with Migrate tools
- The migrations UI only detect those that have been defined as configuration entities using the Migrate Plus module
Day 2 Writing your first Drupal migration
https://agaric.coop/blog/writing-your-first-drupal-migration
cd ~/webapps/ddev-d10$
ddev gen module
File: ~/webapps/ddev-d10/web/modules/ud_migrations_first$ cat ud_migrations_first.info.yml
name: 'ud_migrations_first'
type: module
description: 'ud_migrations_first'
package: Custom
core_version_requirement: ^10 || ^11
dependencies:
- drupal:migrate
File: ~/webapps/ddev-d10/web/modules/ud_migrations_first/migrations/udm_first.yml
id: udm_first
label: 'UD First migration'
source:
plugin: embedded_data
data_rows:
-
unique_id: 1
creative_title: 'The versatility of Drupal fields'
engaging_content: 'Fields are Drupal''s atomic data storage mechanism...'
-
unique_id: 2
creative_title: 'What is a view in Drupal? How do they work?'
engaging_content: 'In Drupal, a view is a listing of information. It can a list of nodes, users, comments, taxonomy terms, files, etc...'
ids:
unique_id:
type: integer
process:
title: creative_title
body: engaging_content
destination:
plugin: 'entity:node'
default_bundle: page
- A quick glimpse at the migration configuration file reveals the three major parts: source, process, and destination.
- We use embedded_data source plugin to define the data to migrate right inside the definition file.
- We use as destination CT page.
pierre@7550 ~/webapps/ddev-d10$ ddev drush pm:enable migrate ud_migrations_first 1 ↵
[success] Successfully installed: migrate, ud_migrations_first
pierre@7550 ~/webapps/ddev-d10$ ddev drush ms
-------------- -------- ------- ---------- ------------- ---------------
Migration ID Status Total Imported Unprocessed Last Imported
-------------- -------- ------- ---------- ------------- ---------------
udm_first Idle 2 0 2
-------------- -------- ------- ---------- ------------- ---------------
pierre@7550 ~/webapps/ddev-d10$ ddev drush migrate:import udm_first 1 ↵
2/2 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
[notice] Processed 2 items (2 created, 0 updated, 0 failed, 0 ignored) in 0.2 seconds (708.9/min) - done with 'udm_first'