use DBIx::Class 0.08100;
use DBIx::Class::Exception;
use Class::Accessor::Grouped;
-use Path::Class qw(dir file);
+use Path::Class qw(dir file tempdir);
use File::Spec::Functions 'catfile', 'catdir';
use Config::Any::JSON;
use Data::Dump::Streamer;
__PACKAGE__->mk_group_accessors( 'simple' => qw/config_dir
_inherited_attributes debug schema_class dumped_objects config_attrs/);
-our $VERSION = '1.001018';
+our $VERSION = '1.001026';
+
+$VERSION = eval $VERSION;
=head1 NAME
ignore_sql_errors => $params->{ignore_sql_errors},
dumped_objects => {},
use_create => $params->{use_create} || 0,
+ use_find_or_create => $params->{use_find_or_create} || 0,
config_attrs => $params->{config_attrs} || {},
};
}
$self->msg("generating fixtures");
- my $tmp_output_dir = dir($output_dir, '-~dump~-' . $<);
+ my $tmp_output_dir = tempdir();
if (-e $tmp_output_dir) {
$self->msg("- clearing existing $tmp_output_dir");
}
$self->msg("- moving temp dir to $output_dir");
- move($_, dir($output_dir, $_->relative($_->parent)->stringify))
- for $tmp_output_dir->children;
+ dircopy($tmp_output_dir, $output_dir);
if (-e $output_dir) {
$self->msg("- clearing tmp dir $tmp_output_dir");
# write dir and gen filename
- my $source_dir = $params->{set_dir}->subdir(lc $src->from);
+ my $source_dir = $params->{set_dir}->subdir($self->_name_for_source($src));
$source_dir->mkpath(0, 0777);
# strip dir separators from file name
$ds{external}->{$field} =
encode_base64( $class
- ->backup($key => $args));
+ ->backup($key => $args),'');
}
}
unless( $pre_schema ) {
return DBIx::Class::Exception->throw('connection details not valid');
}
- my @tables = map { $pre_schema->source($_)->from } $pre_schema->sources;
+ my @tables = map { $self->_name_for_source($pre_schema->source($_)) } $pre_schema->sources;
$self->msg("Tables to drop: [". join(', ', sort @tables) . "]");
my $dbh = $pre_schema->storage->dbh;
# optional, set to 1 to run ddl but not populate
no_populate => 0,
- # optional, set to 1 to run each fixture through ->create rather than have
+ # optional, set to 1 to run each fixture through ->create rather than have
# each $rs populated using $rs->populate. Useful if you have overridden new() logic
- # that effects the value of column(s).
- use_create => 0,
+ # that effects the value of column(s).
+ use_create => 0,
+
+ # optional, same as use_create except with find_or_create.
+ # Useful if you are populating a persistent data store.
+ use_find_or_create => 0,
# Dont try to clean the database, just populate over whats there. Requires
# schema option. Use this if you want to handle removing old data yourself
return 1 if $params->{no_populate};
$self->msg("\nimporting fixtures");
- my $tmp_fixture_dir = dir($fixture_dir, "-~populate~-" . $<);
+ my $tmp_fixture_dir = tempdir();
my $version_file = file($fixture_dir, '_dumper_version');
my $config_set_path = file($fixture_dir, '_config_set');
my $config_set = -e $config_set_path ? do { my $VAR1; eval($config_set_path->slurp); $VAR1 } : '';
}
$self->msg("- creating temp dir");
$tmp_fixture_dir->mkpath();
- for ( map { $schema->source($_)->from } $schema->sources) {
+ for ( map { $self->_name_for_source($schema->source($_)) } $schema->sources) {
my $from_dir = $fixture_dir->subdir($_);
next unless -e $from_dir;
dircopy($from_dir, $tmp_fixture_dir->subdir($_) );
foreach my $source (sort $schema->sources) {
$self->msg("- adding " . $source);
my $rs = $schema->resultset($source);
- my $source_dir = $tmp_fixture_dir->subdir( lc $rs->result_source->from );
+ my $source_dir = $tmp_fixture_dir->subdir( $self->_name_for_source($rs->result_source) );
next unless (-e $source_dir);
my @rows;
while (my $file = $source_dir->next) {
}
if ( $params->{use_create} ) {
$rs->create( $HASH1 );
+ } elsif( $params->{use_find_or_create} ) {
+ $rs->find_or_create( $HASH1 );
} else {
push(@rows, $HASH1);
}
}
}
+# Helper method for ensuring that the name used for a given source
+# is always the same (This is used to name the fixture directories
+# for example)
+
+sub _name_for_source {
+ my ($self, $source) = @_;
+
+ return ref $source->name ? $source->source_name : $source->name;
+}
+
=head1 AUTHOR
Luke Saunders <luke@shadowcatsystems.co.uk>
Frank Switalski <fswitalski@gmail.com>
+ Chris Akins <chris.hexx@gmail.com>
+
=head1 LICENSE
This library is free software under the same license as perl itself