View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Dan Friedman > Class-DBI-DataMigration-0.02 > Class::DBI::DataMigration::Migrator



Annotate this POD


New  1
Open  0
View/Report Bugs

Name ^

Class::DBI::DataMigration::Migrator - Class that does the actual data migration from a source database to a target database.

Synopsis ^

 use Class::DBI::DataMigration::Migrator;

 # Assume we've slurped config.yaml into $yaml (see below for config.yaml contents):
 my $migrator = new Class::DBI::DataMigration::Migrator($yaml);

 # Assume that @source_objs_to_migrate is a list of CDBI objects from
 # the source db that we want to migrate into the target db:
 my $migrated = $migrator->migrate_objects(\@source_objs_to_migrate); 

 # Target db now contains newly-migrated objects.
 # Also, $migrated is a hashref to a list of the migrated objects.

 # ... Meanwhile, in config.yaml:
 # This is an example that migrates from the car table in a source database,
 # called src_db, to the automobile table in a target database, called trg_db.
 # The source car table has make, model, model_year and body_colour columns
 # (body_colour being a has_a relationship to a body_colour table).
 # The target automobile table has brand, type, year, and colour columns
 # corresponding to the respective source columns.
 # For mapping between the has_a relationships (body_colour and colour), a
 # subclass of Mapping, HasAToHasA, is used (see
 # for details).

   base_class: SourceDB::DBI
   db_name: dbi:mysql:src_db
   username: src_uname
   password: src_pass
   base_class: TargetDB::DBI
   db_name: dbi:mysql:trg_db
   username: trg_uname
   password: trg_pass
         target_key: brand
         target_key: type
         target_key: year
         target_key: colour
           class: Class::DBI::DataMigration::Mapping::HasAToHasA
             target_class: TargetDB::DBI::Colour
             target_class_search_key: name
             matching_source_key: body_colour->name
     target_cdbi_class: TargetDB::DBI::Automobile

Methods ^


 my $migrator = Class::DBI::DataMigration::Migrator->new($yaml);

Create and initialize a new instance of this class. Expects a YAML configuration string (see example above) that will be used to initialize the new object's source and target database connections, its entities hash, and its mappers.


Accessor/mutator for a hashref of hashrefs, describing the ways in which data in entities (tables) in the source database will get migrated by this migrator to data in the entities in the target database.


Accessor/mutator for a hashref of mapper objects (see Class::DBI::Mapper), keyed on the various source database entity classes from which this migrator will migrate data.


Expects a reference to a list of source database objects to be migrated. Iterates through the list and calls $self->map() with each source object, collecting and returning a reference to the list of resultant target database objects.


Given a source database object, looks for a mapper object for that object's class in the mappers hash, and calls map() on it with the source object. Returns the result of that map() call (presumably a target database object), or an error message if no suitable mapper could be found.

Author ^

Dan Friedman, <>

Copyright & License ^

Copyright 2004 Dan Friedman, All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Please note that these modules are not products of or supported by the employers of the various contributors to the code.

syntax highlighting: