From: John Napiorkowski Date: Thu, 13 Sep 2012 19:15:56 +0000 (-0400) Subject: if there is a sequence, set it correctly X-Git-Tag: 1.001017~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=75d9325a9e13952710fba323fcbce7909632ed9d;p=dbsrgits%2FDBIx-Class-Fixtures.git if there is a sequence, set it correctly --- diff --git a/Changes b/Changes index a73508a..1154bad 100644 --- a/Changes +++ b/Changes @@ -1,9 +1,10 @@ Revision history for DBIx-Class-Fixtures 1.001016 -- Support more Pg types for datetime_relative (added TIME, DATE, INTERVAL, - TIMESTAMP) -- experimental support for PG SERIAL columns and sequences. +- Support more Postgresql types for datetime_relative (added TIME, DATE, + INTERVAL, TIMESTAMP) +- If $result_source->column_info defines a sequence, make sure we properly + set that sequence to whatever the max value currently is. 1.001015 - ::External::File makes the path if its missing diff --git a/lib/DBIx/Class/Fixtures.pm b/lib/DBIx/Class/Fixtures.pm index 4b1f137..5e0ae7b 100644 --- a/lib/DBIx/Class/Fixtures.pm +++ b/lib/DBIx/Class/Fixtures.pm @@ -1397,11 +1397,31 @@ sub populate { } } $rs->populate(\@rows) if scalar(@rows); + + ## Now we need to do some db specific cleanup + ## this probably belongs in a more isolated space. Right now this is + ## to just handle postgresql SERIAL types that use Sequences + + my $table = $rs->result_source->name; + for my $column(my @columns = $rs->result_source->columns) { + my $info = $rs->result_source->column_info($column); + if(my $sequence = $info->{sequence}) { + $self->msg("- updating sequence $sequence"); + $rs->result_source->storage->dbh_do(sub { + my ($storage, $dbh, @cols) = @_; + $self->msg(my $sql = "SELECT setval('${sequence}', (SELECT max($column) FROM ${table}));"); + my $sth = $dbh->prepare($sql); + my $rv = $sth->execute or die $sth->errstr; + $self->msg("- $sql"); + }); + } + } + } }); }); $self->do_post_ddl( { - schema=>$schema, + schema=>$schema, post_ddl=>$params->{post_ddl} } ) if $params->{post_ddl};