annotate modules/contrib/migrate_plus/migrate_example/README.txt @ 7:848c88cfe644

More layout
author Chris Cannam
date Fri, 05 Jan 2018 13:59:44 +0000
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 INTRODUCTION
Chris@0 2 ------------
Chris@0 3 The migrate_example module demonstrates how to implement custom migrations
Chris@0 4 for Drupal 8. It includes a group of "beer" migrations demonstrating a complete
Chris@0 5 simple migration scenario.
Chris@0 6
Chris@0 7 THE BEER SITE
Chris@0 8 -------------
Chris@0 9 In this scenario, we have a beer aficionado site which stores its data in MySQL
Chris@0 10 tables - there are content items for each beer on the site, user accounts with
Chris@0 11 profile data, categories to classify the beers, and user-generated comments on
Chris@0 12 the beers. We want to convert this site to Drupal with just a few modifications
Chris@0 13 to the basic structure.
Chris@0 14
Chris@0 15 To make the example as simple as to run as possible, the source data is placed
Chris@0 16 in tables directly in your Drupal database - in most real-world scenarios, your
Chris@0 17 source data will be in an external database. The migrate_example_setup submodule
Chris@0 18 creates and populates these tables, as well as configuring your Drupal 8 site
Chris@0 19 (creating a node type, vocabulary, fields, etc.) to receive the data.
Chris@0 20
Chris@0 21 STRUCTURE
Chris@0 22 ---------
Chris@0 23 There are two primary components to this example:
Chris@0 24
Chris@0 25 1. Migration configuration, in the config/install directory. These YAML files
Chris@0 26 describe the migration process and provide the mappings from the source data
Chris@0 27 to Drupal's destination entities. The YAML file names are prefixed with
Chris@0 28 'migrate_plus.migration.' (because, reading from right to left, they define
Chris@0 29 "migration" configuration entities, and the configuration entity type is
Chris@0 30 defined by the "migrate_plus" module).
Chris@0 31
Chris@0 32 2. Source plugins, in src/Plugin/migrate/source. These are referenced from the
Chris@0 33 configuration files, and provide the source data to the migration processing
Chris@0 34 pipeline, as well as manipulating that data where necessary to put it into
Chris@0 35 a canonical form for migrations.
Chris@0 36
Chris@0 37 UNDERSTANDING THE MIGRATIONS
Chris@0 38 ----------------------------
Chris@0 39 The YAML and PHP files are copiously documented in-line. To best understand
Chris@0 40 the concepts described in a more-or-less narrative form, it is recommended you
Chris@0 41 read the files in the following order:
Chris@0 42
Chris@0 43 1. migrate_plus.migration_group.beer.yml
Chris@0 44 2. migrate_plus.migration.beer_term.yml
Chris@0 45 3. BeerTerm.php
Chris@0 46 4. migrate_plus.migration.beer_user.yml
Chris@0 47 5. BeerUser.php
Chris@0 48 6. migrate_plus.migration.beer_node.yml
Chris@0 49 7. BeerNode.php
Chris@0 50 8. migrate_plus.migration.beer_comment.yml
Chris@0 51 9. BeerComment.php
Chris@0 52
Chris@0 53 RUNNING THE MIGRATIONS
Chris@0 54 ----------------------
Chris@0 55 The migrate_tools module (https://www.drupal.org/project/migrate_tools) provides
Chris@0 56 the tools you need to perform migration processes. At this time, the web UI only
Chris@0 57 provides status information - to perform migration operations, you need to use
Chris@0 58 the drush commands.
Chris@0 59
Chris@0 60 # Enable the tools and the example module if you haven't already.
Chris@0 61 drush en -y migrate_tools,migrate_example
Chris@0 62
Chris@0 63 # Look at the migrations. Just look at them. Notice that they are displayed in
Chris@0 64 # the order they will be run, which reflects their dependencies. For example,
Chris@0 65 # because the node migration references the imported terms and users, it must
Chris@0 66 # run after those migrations have been run.
Chris@0 67 drush ms # Abbreviation for migrate-status
Chris@0 68
Chris@0 69 # Run the import operation for all the beer migrations.
Chris@0 70 drush mi --group=beer # Abbreviation for migrate-import
Chris@0 71
Chris@0 72 # Look at what you've done! Also, visit the site and see the imported content,
Chris@0 73 # user accounts, etc.
Chris@0 74 drush ms
Chris@0 75
Chris@0 76 # Look at the duplicate username message.
Chris@0 77 drush mmsg beer_user # Abbreviation for migrate-messages
Chris@0 78
Chris@0 79 # Run the rollback operation for all the migrations (removing all the imported
Chris@0 80 # content, user accounts, etc.). Note that it will rollback the migrations in
Chris@0 81 # the opposite order as they were imported.
Chris@0 82 drush mr --group=beer # Abbreviation for migrate-rollback
Chris@0 83
Chris@0 84 # You can import specific migrations.
Chris@0 85 drush mi beer_term,beer_user
Chris@0 86 # At this point, go look at your content listing - you'll see beer nodes named
Chris@0 87 # "Stub", generated from the user's favbeers references.
Chris@0 88
Chris@0 89 drush mi beer_node,beer_comment
Chris@0 90 # Refresh your content listing - the stub nodes have been filled with real beer!
Chris@0 91
Chris@0 92 # You can rollback specific migrations.
Chris@0 93 drush mr beer_comment,beer_node