X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FVersioned.pm;h=013cbc4f33e3aaa867de3043d67f080a8a6b2104;hb=e7dcdf69fd96a9a50696607171defaf03075592f;hp=74fbd8d2d94ca62ae69ffd383d19abf3240b8afd;hpb=5529838f7afff91467ef2664087999ab222da48d;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Schema/Versioned.pm b/lib/DBIx/Class/Schema/Versioned.pm index 74fbd8d..013cbc4 100644 --- a/lib/DBIx/Class/Schema/Versioned.pm +++ b/lib/DBIx/Class/Schema/Versioned.pm @@ -202,8 +202,7 @@ use warnings; use base 'DBIx::Class::Schema'; use DBIx::Class::Carp; -use Time::HiRes qw/gettimeofday/; -use Try::Tiny; +use DBIx::Class::_Util 'dbic_internal_try'; use Scalar::Util 'weaken'; use namespace::clean; @@ -527,7 +526,7 @@ sub get_db_version my ($self, $rs) = @_; my $vtable = $self->{vschema}->resultset('Table'); - my $version = try { + my $version = dbic_internal_try { $vtable->search({}, { order_by => { -desc => 'installed' }, rows => 1 } ) ->get_column ('version') ->next; @@ -590,10 +589,15 @@ sub _on_connect { my ($self) = @_; - weaken (my $w_self = $self ); + weaken (my $w_storage = $self->storage ); - $self->{vschema} = DBIx::Class::Version->connect(sub { $w_self->storage->dbh }); - my $conn_attrs = $self->storage->_dbic_connect_attributes || {}; + $self->{vschema} = DBIx::Class::Version->connect( + sub { $w_storage->dbh }, + + # proxy some flags from the main storage + { map { $_ => $w_storage->$_ } qw( unsafe ) }, + ); + my $conn_attrs = $w_storage->_dbic_connect_attributes || {}; my $vtable = $self->{vschema}->resultset('Table'); @@ -602,11 +606,11 @@ sub _on_connect # check for legacy versions table and move to new if exists unless ($self->_source_exists($vtable)) { - my $vtable_compat = DBIx::Class::VersionCompat->connect(sub { $w_self->storage->dbh })->resultset('TableCompat'); + my $vtable_compat = DBIx::Class::VersionCompat->connect(sub { $w_storage->dbh })->resultset('TableCompat'); if ($self->_source_exists($vtable_compat)) { $self->{vschema}->deploy; map { $vtable->new_result({ installed => $_->Installed, version => $_->Version })->insert } $vtable_compat->all; - $self->storage->_get_dbh->do("DROP TABLE " . $vtable_compat->result_source->from); + $w_storage->_get_dbh->do("DROP TABLE " . $vtable_compat->result_source->from); } } @@ -642,8 +646,9 @@ sub _create_db_to_schema_diff { return; } - unless (DBIx::Class::Optional::Dependencies->req_ok_for ('deploy')) { - $self->throw_exception("Unable to proceed without " . DBIx::Class::Optional::Dependencies->req_missing_for ('deploy') ); + require DBIx::Class::Optional::Dependencies; + if ( my $missing = DBIx::Class::Optional::Dependencies->req_missing_for('deploy') ) { + $self->throw_exception("Unable to proceed without $missing"); } my $db_tr = SQL::Translator->new({ @@ -710,7 +715,8 @@ sub _set_db_version { # not possible to format the string sanely, as the column is a varchar(20). # The 'v' character is added to the front of the string, so that any version # formatted by this new function will sort _after_ any existing 200... strings. - my @tm = gettimeofday(); + require Time::HiRes; + my @tm = Time::HiRes::gettimeofday(); my @dt = gmtime ($tm[0]); my $o = $vtable->new_result({ version => $version, @@ -746,23 +752,28 @@ sub _read_sql_file { sub _source_exists { - my ($self, $rs) = @_; - - return try { - $rs->search(\'1=0')->cursor->next; - 1; - } catch { - 0; - }; + my ($self, $rs) = @_; + + ( dbic_internal_try { + $rs->search(\'1=0')->cursor->next; + 1; + } ) + ? 1 + : 0 + ; } -1; +=head1 FURTHER QUESTIONS? +Check the list of L. -=head1 AUTHOR AND CONTRIBUTORS +=head1 COPYRIGHT AND LICENSE -See L and L in DBIx::Class +This module is free software L +by the L. You can +redistribute it and/or modify it under the same terms as the +L. -=head1 LICENSE +=cut -You may distribute this code under the same terms as Perl itself. +1;