Class::DBI::DataMigration::Migrator - Class that does the actual data migration from a source database to a target database.
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 # Class::DBI::DataMigration::Mapping::HasAToHasA.pm for details). --- source_connection: base_class: SourceDB::DBI db_name: dbi:mysql:src_db username: src_uname password: src_pass target_connection: base_class: TargetDB::DBI db_name: dbi:mysql:trg_db username: trg_uname password: trg_pass entities: SourceDB::DBI::Car: mappings: make: target_key: brand model: target_key: type model_year: target_key: year body_colour: target_key: colour mapping: class: Class::DBI::DataMigration::Mapping::HasAToHasA config: target_class: TargetDB::DBI::Colour target_class_search_key: name matching_source_key: body_colour->name target_cdbi_class: TargetDB::DBI::Automobile
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.
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.