Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Drupal 8 - Writing dynamic migrations

Drupal 8 - Writing dynamic migrations

Mohit Aghera

March 10, 2018
Tweet

More Decks by Mohit Aghera

Other Decks in Technology

Transcript

  1. 1
    axelerant.com
    How to write dynamic migrations
    Mohit Aghera, Nikunj Kotecha

    View Slide

  2. 2
    axelerant.com
    About Us
    Mohit Aghera
    - Does development nowadays in Drupal 8 and at times Behat
    - Known on drupal.org as mohit_aghera
    - Known on twitter.com as @mohit_rocks
    Nikunj Kotecha
    - Does development nowadays in Drupal 8 and at times in Magento 2
    - Known on drupal.org as nikunjkotecha
    - Known on twitter.com as @nikunjhk

    View Slide

  3. 3
    axelerant.com
    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

    View Slide

  4. 4
    axelerant.com
    Possible approaches for migration
    ● Migration templates
    ● Config Entities

    View Slide

  5. 5
    axelerant.com
    Migration as Configuration entities
    ● Similar to any configurations
    ● Resides in [module]/config directory
    ● Typically names are given like
    “migrate.migration.node_page.yml”

    View Slide

  6. 6
    axelerant.com
    Migration as Configuration entities
    Advantages:
    ● Easy to write and run
    ● No need to write specific logic to run unlike migration
    templates
    Disadvantages:
    ● Not much flexible
    ● Hard to change runtime
    ● Dynamic migration generation is not possible
    ● Can’t generate based on user inputs

    View Slide

  7. 7
    axelerant.com
    Migration as templates
    ● Resides in [module]/migration_templates directory
    ● Names could match the migration id
    ● Typically names are given like “node_page.yml”

    View Slide

  8. 8
    axelerant.com
    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

    View Slide

  9. 9
    axelerant.com
    Dynamic Migrations
    ● Drupal 8 core uses templates to generate migration
    ● When we use Drupal 7 to Drupal 8 migration upgrader it
    will generate migrations dynamically and import content

    View Slide

  10. 10
    axelerant.com
    Deriver
    plugins
    ● Works as a derivative
    for new migrations
    ● Helps to create
    migrations dynamically
    ● Extends DeriverBase
    class.

    View Slide

  11. 11
    axelerant.com
    Writing
    Derivers
    ● Implement
    getDerivativeDefinitions()
    and write your logic.

    View Slide

  12. 12
    axelerant.com
    Using Derivers
    Specify in migration template file.

    View Slide

  13. 13
    axelerant.com
    Running migration

    View Slide

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

    View Slide

  15. 15
    axelerant.com
    Thank you … for being here and allowing
    us to contribute and share our knowledge
    To summarise…
    ● We discussed how to make migrations more
    dynamic and less painful
    ● We saw an example of how to write derivers
    ● We saw advantages of doing it, it is done in Core
    and many contrib modules already

    View Slide

  16. 16
    axelerant.com
    References
    Migration API : https://www.drupal.org/docs/8/api/migrate-api/migrate-api-overview
    Reference module : https://github.com/mohit-rocks/drupalcamp-goa

    View Slide