From: luke saunders Date: Tue, 5 Jan 2010 16:02:46 +0000 (+0100) Subject: force transactions X-Git-Tag: 1.001011~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7f25d8f86a859af57d5bc637162b1a761c05d962;p=dbsrgits%2FDBIx-Class-Fixtures.git force transactions --- diff --git a/Changes b/Changes index 5c0efcb..2a19336 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Revision history for DBIx-Class-Fixtures +- Force operations to work inside a transaction so with_deferred_fks actually works. + 1.001008 - Man, I should test better. diff --git a/lib/DBIx/Class/Fixtures.pm b/lib/DBIx/Class/Fixtures.pm index 974ad06..b5bae49 100644 --- a/lib/DBIx/Class/Fixtures.pm +++ b/lib/DBIx/Class/Fixtures.pm @@ -863,12 +863,14 @@ sub _generate_schema { # clear existing db $self->msg("- clearing DB of existing tables"); - $pre_schema->storage->with_deferred_fk_checks(sub { - foreach my $table (@tables) { - eval { - $dbh->do("drop table $table" . ($params->{cascade} ? ' cascade' : '') ) - }; - } + $pre_schema->storage->txn_do(sub { + $pre_schema->storage->with_deferred_fk_checks(sub { + foreach my $table (@tables) { + eval { + $dbh->do("drop table $table" . ($params->{cascade} ? ' cascade' : '') ) + }; + } + }); }); # import new ddl file to db @@ -1042,26 +1044,27 @@ sub populate { $fixup_visitor = new Data::Visitor::Callback(%callbacks); } - $schema->storage->with_deferred_fk_checks(sub { - 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 ); - next unless (-e $source_dir); - my @rows; - while (my $file = $source_dir->next) { - next unless ($file =~ /\.fix$/); - next if $file->is_dir; - my $contents = $file->slurp; - my $HASH1; - eval($contents); - $HASH1 = $fixup_visitor->visit($HASH1) if $fixup_visitor; - push(@rows, $HASH1); + $schema->storage->txn_do(sub { + $schema->storage->with_deferred_fk_checks(sub { + 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 ); + next unless (-e $source_dir); + my @rows; + while (my $file = $source_dir->next) { + next unless ($file =~ /\.fix$/); + next if $file->is_dir; + my $contents = $file->slurp; + my $HASH1; + eval($contents); + $HASH1 = $fixup_visitor->visit($HASH1) if $fixup_visitor; + push(@rows, $HASH1); + } + $rs->populate(\@rows) if scalar(@rows); } - $rs->populate(\@rows) if scalar(@rows); - } + }); }); - $self->do_post_ddl( { schema=>$schema, post_ddl=>$params->{post_ddl}