sub init_schema {
my $self = shift;
my %args = @_;
+
my $db_file = "t/var/DBIxClass.db";
- unlink($db_file) if -e $db_file;
- unlink($db_file . "-journal") if -e $db_file . "-journal";
mkdir("t/var") unless -d "t/var";
+ if ( !$args{no_deploy} ) {
+ unlink($db_file) if -e $db_file;
+ unlink($db_file . "-journal") if -e $db_file . "-journal";
+ }
- my $dsn = $ENV{"FIXTURETEST_DSN"} || "dbi:SQLite:${db_file}";
- my $dbuser = $ENV{"FIXTURETEST_DBUSER"} || '';
- my $dbpass = $ENV{"FIXTURETEST_DBPASS"} || '';
+ my $dsn = $args{"dsn"} || "dbi:SQLite:${db_file}";
+ my $dbuser = $args{"user"} || '';
+ my $dbpass = $args{"pass"} || '';
my $schema;
$schema = DBICTest::Schema->compose_namespace('DBICTest')
->connect(@connect_info);
}
- $schema->storage->on_connect_do(['PRAGMA synchronous = OFF']);
+
if ( !$args{no_deploy} ) {
__PACKAGE__->deploy_schema( $schema );
__PACKAGE__->populate_schema( $schema ) if( !$args{no_populate} );
return $schema;
}
+
+sub get_ddl_file {
+ my $self = shift;
+ my $schema = shift;
+
+ return 't/lib/' . lc($schema->storage->dbh->{Driver}->{Name}) . '.sql';
+}
+
=head2 deploy_schema
DBICTest->deploy_schema( $schema );
my $self = shift;
my $schema = shift;
- open IN, "t/lib/sqlite.sql";
+ my $file = shift || $self->get_ddl_file($schema);
+ open( my $fh, "<",$file ) or die "couldnt open $file, $!";
my $sql;
- { local $/ = undef; $sql = <IN>; }
- close IN;
- ($schema->storage->dbh->do($_) || print "Error on SQL: $_\n") for split(/;\n/, $sql);
+ { local $/ = undef; $sql = <$fh>; }
+
+ foreach my $line (split(/;\n/, $sql)) {
+ print "$line\n";
+ next if(!$line);
+ next if($line =~ /^--/);
+ next if($line =~ /^BEGIN TRANSACTION/m);
+ next if($line =~ /^COMMIT/m);
+ next if $line =~ /^\s+$/; # skip whitespace only
+
+ $schema->storage->dbh->do($line) || print "Error on SQL: $line\n";
+ }
}
+
+
+=head2 clear_schema
+
+ DBICTest->clear_schema( $schema );
+
+=cut
+
+sub clear_schema {
+ my $self = shift;
+ my $schema = shift;
+
+ foreach my $class ($schema->sources) {
+ $schema->resultset($class)->delete;
+ }
+}
+
=head2 populate_schema
[ 1, 'Caterwauler McCrae' ],
[ 2, 'Random Boy Band' ],
[ 3, 'We Are Goth' ],
+ [ 4, '' ], # Test overridden new will default name to "Test Name" using use_create => 1.
+ [ 32948, 'Big PK' ],
]);
$schema->populate('CD', [
[ 2, 1, "Forkful of bees", 2001 ],
[ 3, 1, "Caterwaulin' Blues", 1997 ],
[ 4, 2, "Generic Manufactured Singles", 2001 ],
- [ 5, 3, "Come Be Depressed With Us", 1998 ],
+ [ 5, 2, "We like girls and stuff", 2003 ],
+ [ 6, 3, "Come Be Depressed With Us", 1998 ],
]);
$schema->populate('Tag', [
[ 1, 1 ],
[ 1, 2 ],
[ 1, 3 ],
+ [ 2, 1 ],
+ [ 2, 2 ],
+ [ 3, 3 ],
]);
$schema->populate('Track', [
- [ qw/trackid cd position title/ ],
+ [ qw/trackid cd position title last_updated_on/ ],
[ 4, 2, 1, "Stung with Success"],
[ 5, 2, 2, "Stripy"],
[ 6, 2, 3, "Sticky Honey"],
[ 7, 3, 1, "Yowlin"],
[ 8, 3, 2, "Howlin"],
- [ 9, 3, 3, "Fowlin"],
+ [ 9, 3, 3, "Fowlin", '2007-10-20 00:00:00'],
[ 10, 4, 1, "Boring Name"],
[ 11, 4, 2, "Boring Song"],
[ 12, 4, 3, "No More Ideas"],