use File::Copy qw/move/;
use Hash::Merge qw( merge );
use Data::Dumper;
+use Class::C3::Componentised;
use base qw(Class::Accessor::Grouped);
-our %db_to_parser = (
- 'mysql' => 'DateTime::Format::MySQL',
- 'pg' => 'DateTime::Format::Pg',
-);
+our $namespace_counter = 0;
__PACKAGE__->mk_group_accessors( 'simple' => qw/config_dir _inherited_attributes debug schema_class/);
my $pre_schema;
my $connection_details = $params->{connection_details};
- unless( $pre_schema = $schema_class->connect(@{$connection_details}) ) {
+ $namespace_counter++;
+ my $namespace = "DBIx::Class::Fixtures::GeneratedSchema_" . $namespace_counter;
+ Class::C3::Componentised->inject_base( $namespace => $schema_class );
+ $pre_schema = $namespace->connect(@{$connection_details});
+ 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 { $pre_schema->source($_)->from } $pre_schema->sources;
my $dbh = $pre_schema->storage->dbh;
# clear existing db
# load schema object from our new DB
$self->msg("- loading fresh DBIC object from DB");
- my $schema = $schema_class->connect(@{$connection_details});
+ my $schema = $namespace->connect(@{$connection_details});
return $schema;
}
--- /dev/null
+#!perl
+
+use DBIx::Class::Fixtures;
+use Test::More tests => 7;
+use lib qw(t/lib);
+use DBICTest;
+use Path::Class;
+use Data::Dumper;
+use DBICTest::Schema2;
+
+# set up and populate normal schema
+ok(my $schema = DBICTest->init_schema(), 'got schema');
+my $config_dir = 't/var/configs';
+
+my @different_connection_details = ('dbi:SQLite:t/var/DBIxClassDifferent.db', '', '');
+ok(my $schema2 = DBICTest::Schema2->compose_namespace('DBICTest2')->connect(@different_connection_details));
+unlink('t/var/DBIxClassDifferent.db') if (-e 't/var/DBIxClassDifferent.db');
+DBICTest->deploy_schema($schema2, 't/lib/sqlite_different.sql');
+# do dump
+ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir');
+ok($fixtures->dump({ config => "simple.json", schema => $schema, directory => 't/var/fixtures' }), "simple dump executed okay");
+
+ok($fixtures->populate({ ddl => 't/lib/sqlite_different.sql', connection_details => [@different_connection_details], directory => 't/var/fixtures' }), 'mysql populate okay');
+ok($fixtures->populate({ ddl => 't/lib/sqlite.sql', connection_details => ['dbi:SQLite:t/var/DBIxClass.db', '', ''], directory => 't/var/fixtures' }), 'sqlite populate okay');
+
+is($schema->resultset('Artist')->count, 1, 'artist imported to sqlite okay');