[Dbix-class] copying between databases
David Kamholz
davekam at pobox.com
Thu Feb 9 04:31:59 CET 2006
This should do it, but it may be a bit more insert-happy than you
want. It might be good to be able to tell it more precisely where to
stop. It shouldn't end up in an infinite loop though, at least.
Dave
sub migrate_obj {
my ($obj,$dest_schema) = @_;
my $dest_rs = $dest_schema->resultset(ref $obj);
my $cols = { $obj->get_columns };
unless ($dest_rs->find($cols)) {
my $dest_obj = $dest_rs->create($cols);
_migrate_obj_rels($obj,$dest_obj);
}
}
sub _migrate_obj_rels {
my ($obj,$dest_obj) = @_;
foreach my $rel ($obj->relationships) {
my $rs = $obj->search_related($rel);
while (my $rel_obj = $rs->next) {
my $cols = { $rel_obj->get_columns };
unless ($dest_obj->find_related($rel, $cols)) {
my $dest_rel_obj = $dest_obj->create_related($rel,
$cols);
_migrate_obj_rels($rel_obj,$dest_rel_obj);
}
}
}
}
More information about the Dbix-class
mailing list