Slide 1

Slide 1 text

LISBON 2018 DRUPAL DEVELOPER DAYS Writing Dynamic Migrations Mohit Aghera

Slide 2

Slide 2 text

Diamond Sponsor

Slide 3

Slide 3 text

Platinum Sponsors

Slide 4

Slide 4 text

Gold Sponsors

Slide 5

Slide 5 text

Special Thanks to..

Slide 6

Slide 6 text

Mohit Aghera • Back-end developer @Axelerant • Drupal.org: mohit_aghera • Twitter: @mohit_rocks About Me

Slide 7

Slide 7 text

Dynamic Migrations • What are dynamic migrations ? • Why do we need it ?

Slide 8

Slide 8 text

Quick Recap !!!

Slide 9

Slide 9 text

Migrations : A Brief Introduction What Migrate API Provides: • Migrate Data from source to destination • Keeps track of record of migrated data • Provides framework for writing migrations

Slide 10

Slide 10 text

Migration Plugins • Source Plugins • Process Plugin • Destination Plugins • And many more...

Slide 11

Slide 11 text

Migration Flow

Slide 12

Slide 12 text

Understanding Derivatives • Drupal 7 has “_info()” hooks • Wonder how do we generate multiple blocks with single block plugin ? • Drupal 8 has “Derivatives” • Allows to generate instances dynamically

Slide 13

Slide 13 text

How Derivative Works? • Plugin manager uses ”Discovery” mechanism • DerivativeDiscoveryDecorator” decorator class

Slide 14

Slide 14 text

Define Along with Plugins

Slide 15

Slide 15 text

Deriver Implementation SystemMenuBlock Deriver implementation:

Slide 16

Slide 16 text

Derivatives Examples Notable Examples: • SystemMenuBlock • BlockContentBlock • LanguageBlock And many more..

Slide 17

Slide 17 text

Possible approaches for Migration • Configuration Entities • Migration Templates

Slide 18

Slide 18 text

Migration as Configuration Entities • Similar to any configurations • Resides in [module]/config directory • Typically names are given like “migrate.migration.node_page.yml”

Slide 19

Slide 19 text

Migration as Configuration Entities Advantages: • Easy to write and run • No need to write specific logic to run unlike migration templates

Slide 20

Slide 20 text

Migration as Configuration Entities Disadvantages: • Not much flexible • Dynamic migration generation is not possible • Can’t generate based on user inputs

Slide 21

Slide 21 text

Migration as Templates • Resides in [module]/migration_templates directory • Names could match the migration id • Typically names are given like “node_page.yml”

Slide 22

Slide 22 text

Migration as Templates Advantages: • Much more flexible than configuration entities for each variation • Easy to change runtime • Ability to generate dynamic migration using reusable templates

Slide 23

Slide 23 text

Derivers for Migrations Works as Derivates for Migrations Creates migrations dynamically Extends “DeriverBase” class

Slide 24

Slide 24 text

Writing Derivers Implement getDerivativeDefinitions() and write your logic.

Slide 25

Slide 25 text

Using Derivers Specify in migrations template file

Slide 26

Slide 26 text

Running Migrations

Slide 27

Slide 27 text

Use cases ● Migrating large amount of sites with similar architecture but different languages in each site (our use case, https://github.com/mohit-rocks/drupal-days) ● Core: Migrating D7 to D8 ● Core: Migrating Workbench Moderation to Content Moderation (https://www.drupal.org/project/wbm2cm) ● And many more...

Slide 28

Slide 28 text

LISBON 2018 DRUPAL DEVELOPER DAYS Thank you !!!