X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flib%2FDBICTest.pm;h=08c0e27ae7516d23a14418eaf33014db2766d1c6;hb=a9fe6f36ac3d911da91bc28f2c473ddf1d98008c;hp=c3059cea648f1e2d95601696326b49ffcd15a1ae;hpb=3c5282523430b124143cbc5d98f33cb149e9806d;p=dbsrgits%2FDBIx-Class-Fixtures.git diff --git a/t/lib/DBICTest.pm b/t/lib/DBICTest.pm index c3059ce..08c0e27 100755 --- a/t/lib/DBICTest.pm +++ b/t/lib/DBICTest.pm @@ -45,15 +45,18 @@ default, unless the no_deploy or no_populate flags are set. 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; @@ -67,7 +70,7 @@ sub init_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} ); @@ -75,6 +78,14 @@ sub init_schema { 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 ); @@ -85,11 +96,21 @@ sub deploy_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 = ; } - 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"; + } } @@ -127,6 +148,8 @@ sub 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', [ @@ -164,16 +187,19 @@ sub populate_schema { [ 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"],