SlideShare une entreprise Scribd logo
1  sur  13
Télécharger pour lire hors ligne
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/

Contenu connexe

Similaire à Migrating data into Drupal using the migrate module

Automating Drupal Migrations
Automating Drupal MigrationsAutomating Drupal Migrations
Automating Drupal MigrationslittleMAS
 
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 ModuleSrijan Technologies
 
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 RisksAcquia
 
Drupal content-migration
Drupal content-migrationDrupal content-migration
Drupal content-migrationAshok Modi
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practicesmanugoel2003
 
Spark Structured APIs
Spark Structured APIsSpark Structured APIs
Spark Structured APIsKnoldus Inc.
 
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 2011camp_drupal_ua
 
Drupal II: The SQL
Drupal II: The SQLDrupal II: The SQL
Drupal II: The SQLddiers
 
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
 
Addressing Scenario
Addressing ScenarioAddressing Scenario
Addressing ScenarioTara Hardin
 
Multilingualism makes better programmers
Multilingualism makes better programmersMultilingualism makes better programmers
Multilingualism makes better programmersAlexander Varwijk
 
Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010Drupal Module Development - OSI Days 2010
Drupal Module Development - OSI Days 2010Siva Epari
 
Drupal Module Development
Drupal Module DevelopmentDrupal Module Development
Drupal Module Developmentipsitamishra
 
Getting Started with DrupalGap
Getting Started with DrupalGapGetting Started with DrupalGap
Getting Started with DrupalGapAlex S
 

Similaire à 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
 

Dernier

Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
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 WorkerThousandEyes
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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...apidays
 
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 MenDelhi Call girls
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
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 productivityPrincipled Technologies
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
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 Processorsdebabhi2
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 

Dernier (20)

Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 

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/