Dan Friedman > Class-DBI-DataMigration-0.02 > Class::DBI::DataMigration::Synchronizer

Download:
Class-DBI-DataMigration-0.02.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

Name ^

Class::DBI::DataMigration::Synchronizer

Synopsis ^

 use Class::DBI::DataMigration::Synchronizer;

 my $synch = Class::DBI::DataMigration::Synchronizer->new(
    search_criteria => \%search_criteria);
 my $synched_objects = $synch->synchronize;

Description ^

Class::DBI::DataMigration::Synchronizer - Keep records synchronized between source and target databases.

Methods ^

config_path

Class accessor/mutator for the directory in which our config.yaml can be found. This config.yaml will be used to build a Class::DBI::DataMigration::Migrator, which we will then use to synchronize the appropriate data. Defaults to './'.

search_criteria

Accessor/mutator for a hashref of hashes of search criteria to use, per table, to locate objects for migration between the source and target databases.

The hash should be keyed on source db CDBI class names, with hashrefs of key/value pairs to search for in each class as values; these latter key/value hashes will be used to search() each class. Classes whose values are empty hashes will have retrieve_all() called on them -- that is, *all* objects in that class will be migrated. For example:

 { 
    SourceClass1 => { 
        key1 => value1, 
        key2 => value2 
    },                                    # migrate objects in SourceClass1 that match
                                          # key1 => value1, key2 => value2

    SourceClass2 => {}                    # migrate all objects in SourceClass2
 }

new

This constructor uses Getopt::Long to parse command-line arguments, producing a search_criteria hash suitable for use at synchronize() time.

 --table=class1,key1,value1,key2,value2... --table=class2,key3,value3... --table=class3...

The keys and values supplied for each --table argument will be used to search() the given class for objects to be migrated. If no keys/values are given, *all* objects in the class (i.e., all rows in the table) will be migrated. So, in the example above, the search_criteria hashref produced would be:

 {
    class1 => {
        key1 => value1,
        key2 => value2
    },

    class2 => {
        key3 => value3
    },

    class3 => {}
 }

Class/key/value lists must contain no spaces and be separated by commas, as in the example above.

synchronize

Collect together all objects from the various CDBI classes matching our search_criteria; build a migrator for our class's config.yaml file and migrate the objects we've collected.

NB: our config.yaml file is expected to be found in config_path(), which defaults to ./.

Author ^

Dan Friedman, <lamech@cpan.org>

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: