README.txt 5.0 KB

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