SlideShare a Scribd company logo
1 of 13
Download to read offline
Migrating data into Drupal
using the migrate module


       Oxford DrupalCamp
       Friday 22 June, 2012

         Johan Gant
What's involved?
 Migrate me an army of
         data!




      Uh, oh!!
What's involved?
                Planning/analysis




Tech/dev work                       Acceptance




                                      Done!
Successful migrations
Move data from A to B in a planned, methodical manner.

Repeatable
Measurable
Work with realistic data

Safe
             Use the right tools for the task

      The complexity of your solution should be driven by
               the task at hand, not your tech
When stuff goes wrong...
Un...
          Safe
         Reliable
         Planned
          Done


Upset...
        Processes
         Clients
        Developers

                     RAGEBALLS FOR EVERYONE
Drupal migrate module
Provides a great framework for moving content into Drupal
Encourages good habits
Drush support
migrate_ui adds a nice front end
The Drupal way – so other Drupal devs can
pick up your work without too much bother.

Not a one stop shop for migrations


Use the right tools, or combination of
tools, to get the job done.


                                               Let's look at some code
<?php
class DemoMigration extends Migration {
  public function __construct() {
    parent::construct();
    $this->description = t('A sample migration module');

        // Define the map between your source and destination
        $this->map = new MigrateSQLMap(
          $this->machineName, // defaults to your migration class name
          array(
             'id' => array(
               'type' => 'int',
               ....
             ),                                                        http://drupal.org/node/1528934
          ),
          MigrateDestinationNode::getKeySchema();
        );

        // Define the fields from your source
        $source_fields = array(
          'id' => t('description'),
          'field1' => t('Node title'),
          .....
        );

        $query = db_select('source_table_name', 'sql-alias')
                   ->fields('alias', array_keys($source_fields))
                   ->orderBy('id', 'ASC');

        $this->source = new MigrateSourceSQL($query);

        // Define what sort of destination you have
        // - options include Nodes, Terms, Users and Comments
        $this->destination = new MigrateDestinationNode('node_machine_name');

        // Define your field mappings - nice options include default values (can include PHP),
        // groupings, callbacks – see beer.inc example class for details
        $this->addFieldMapping('source_body', 'field_body')
          ->defaultValue('Wibble'),
        .....
    }
}
/**
  * Useful function to help 'massage' your awkward source data into shape
  */
public function prepareRow($row) {
   // Convert ISO date to UNIX timestamp
   if ($row->created_at) {
     $row->created_at = strtotime($row->created_at);
   }
}


Handling taxonomy terms
/**
 * Term syntax/format a bit awkward,depends on whether you're using tid or name.
 * Migrate module will match on tid or name and handle the rest for you :)
 */
$this->addFieldMapping('source_col_name', 'terms')
  ->arguments(array('source_type' => 'name')), // use tid if you've got term ids
  ->separator('$$'); // Used to split long string of term names in source


Handling node reference fields

/**
  * Not documented when I used migrate, but expects a nid
  */
if ($row->some-identifier) {
   $row->reference_nid = my_own_function_to_lookup_a_nid($row->some_identifier);
}
Migration!


Rails/PostgreSQL > Drupal 6

Export data into CSV, import into Drupal db via table
wizard module
Pre-migration script to create image nodes
Run migration

Client demo and deployment
5 days from start to finish
Problems!


               Steep(ish) learning curve

    Documentation a bit sparse in places

         Awkward handling of taxonomy,
        node reference, and domain data

                   Pre-migration fudges

                           Performance
Should I use Drupal migrate?
Yes / absolutely / do it now                Probably not

●   Want to move a reasonable           ●   Low volume or low complexity
    volume of data INTO Drupal from
    MySQL/XML/JSON/CSV
                                        ●   Not familiar with coding

●   Have complex data mappings that
                                        ●   Already got something that works
    are best expressed                      well
    programmatically                    ●   Trying to move data OUT of Drupal
●   Make best use of Drupal tools and       to somewhere else
    existing code
●   Want to recycle code between
    projects
Drupal migrate - resources
●   Migrate module page -
    http://drupal.org/project/migrate
●   Economist migration (great summary) -
    http://drupal.org/node/915102
●   Torchbox Team Drupal blog -
    http://drupalblog.torchbox.com/

More Related Content

Similar to Migrating data into Drupal using the migrate module

Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
camp_drupal_ua
 
Codebits 2012 - Fast relational web site construction.
Codebits 2012 - Fast relational web site construction.Codebits 2012 - Fast relational web site construction.
Codebits 2012 - Fast relational web site construction.
Nelson Gomes
 

Similar to Migrating data into Drupal using the migrate module (20)

Automating Drupal Migrations
Automating Drupal MigrationsAutomating Drupal Migrations
Automating Drupal Migrations
 
Data migration to Drupal using Migrate Module
Data migration to Drupal using Migrate ModuleData migration to Drupal using Migrate Module
Data migration to Drupal using Migrate Module
 
Drupal 8 migrate!
Drupal 8 migrate!Drupal 8 migrate!
Drupal 8 migrate!
 
Migrating to Drupal 8: How to Migrate Your Content and Minimize the Risks
Migrating to Drupal 8: How to Migrate Your Content and Minimize the RisksMigrating to Drupal 8: How to Migrate Your Content and Minimize the Risks
Migrating to Drupal 8: How to Migrate Your Content and Minimize the Risks
 
Migrating data to drupal 8
Migrating data to drupal 8Migrating data to drupal 8
Migrating data to drupal 8
 
Drupal 8 migrate!
Drupal 8 migrate!Drupal 8 migrate!
Drupal 8 migrate!
 
Migrate
MigrateMigrate
Migrate
 
Migrations
MigrationsMigrations
Migrations
 
Drupal content-migration
Drupal content-migrationDrupal content-migration
Drupal content-migration
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
Spark Structured APIs
Spark Structured APIsSpark Structured APIs
Spark Structured APIs
 
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
Andriy Podanenko.Drupal database api.DrupalCamp Kyiv 2011
 
Drupal II: The SQL
Drupal II: The SQLDrupal II: The SQL
Drupal II: The SQL
 
Codebits 2012 - Fast relational web site construction.
Codebits 2012 - Fast relational web site construction.Codebits 2012 - Fast relational web site construction.
Codebits 2012 - Fast relational web site construction.
 
Addressing Scenario
Addressing ScenarioAddressing Scenario
Addressing Scenario
 
Multilingualism makes better programmers
Multilingualism makes better programmersMultilingualism makes better programmers
Multilingualism makes better programmers
 
Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010
 
Drupal Module Development
Drupal Module DevelopmentDrupal Module Development
Drupal Module Development
 
Building Custom PHP Extensions
Building Custom PHP ExtensionsBuilding Custom PHP Extensions
Building Custom PHP Extensions
 
Getting Started with DrupalGap
Getting Started with DrupalGapGetting Started with DrupalGap
Getting Started with DrupalGap
 

Recently uploaded

Recently uploaded (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

Migrating data into Drupal using the migrate module

  • 1. Migrating data into Drupal using the migrate module Oxford DrupalCamp Friday 22 June, 2012 Johan Gant
  • 2. What's involved? Migrate me an army of data! Uh, oh!!
  • 3. What's involved? Planning/analysis Tech/dev work Acceptance Done!
  • 4. Successful migrations Move data from A to B in a planned, methodical manner. Repeatable Measurable Work with realistic data Safe Use the right tools for the task The complexity of your solution should be driven by the task at hand, not your tech
  • 5. When stuff goes wrong... Un... Safe Reliable Planned Done Upset... Processes Clients Developers RAGEBALLS FOR EVERYONE
  • 6. Drupal migrate module Provides a great framework for moving content into Drupal Encourages good habits Drush support migrate_ui adds a nice front end The Drupal way – so other Drupal devs can pick up your work without too much bother. Not a one stop shop for migrations Use the right tools, or combination of tools, to get the job done. Let's look at some code
  • 7. <?php class DemoMigration extends Migration { public function __construct() { parent::construct(); $this->description = t('A sample migration module'); // Define the map between your source and destination $this->map = new MigrateSQLMap( $this->machineName, // defaults to your migration class name array( 'id' => array( 'type' => 'int', .... ), http://drupal.org/node/1528934 ), MigrateDestinationNode::getKeySchema(); ); // Define the fields from your source $source_fields = array( 'id' => t('description'), 'field1' => t('Node title'), ..... ); $query = db_select('source_table_name', 'sql-alias') ->fields('alias', array_keys($source_fields)) ->orderBy('id', 'ASC'); $this->source = new MigrateSourceSQL($query); // Define what sort of destination you have // - options include Nodes, Terms, Users and Comments $this->destination = new MigrateDestinationNode('node_machine_name'); // Define your field mappings - nice options include default values (can include PHP), // groupings, callbacks – see beer.inc example class for details $this->addFieldMapping('source_body', 'field_body') ->defaultValue('Wibble'), ..... } }
  • 8. /** * Useful function to help 'massage' your awkward source data into shape */ public function prepareRow($row) { // Convert ISO date to UNIX timestamp if ($row->created_at) { $row->created_at = strtotime($row->created_at); } } Handling taxonomy terms /** * Term syntax/format a bit awkward,depends on whether you're using tid or name. * Migrate module will match on tid or name and handle the rest for you :) */ $this->addFieldMapping('source_col_name', 'terms') ->arguments(array('source_type' => 'name')), // use tid if you've got term ids ->separator('$$'); // Used to split long string of term names in source Handling node reference fields /** * Not documented when I used migrate, but expects a nid */ if ($row->some-identifier) { $row->reference_nid = my_own_function_to_lookup_a_nid($row->some_identifier); }
  • 9. Migration! Rails/PostgreSQL > Drupal 6 Export data into CSV, import into Drupal db via table wizard module Pre-migration script to create image nodes Run migration Client demo and deployment 5 days from start to finish
  • 10. Problems! Steep(ish) learning curve Documentation a bit sparse in places Awkward handling of taxonomy, node reference, and domain data Pre-migration fudges Performance
  • 11.
  • 12. Should I use Drupal migrate? Yes / absolutely / do it now Probably not ● Want to move a reasonable ● Low volume or low complexity volume of data INTO Drupal from MySQL/XML/JSON/CSV ● Not familiar with coding ● Have complex data mappings that ● Already got something that works are best expressed well programmatically ● Trying to move data OUT of Drupal ● Make best use of Drupal tools and to somewhere else existing code ● Want to recycle code between projects
  • 13. Drupal migrate - resources ● Migrate module page - http://drupal.org/project/migrate ● Economist migration (great summary) - http://drupal.org/node/915102 ● Torchbox Team Drupal blog - http://drupalblog.torchbox.com/