X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FVersioned.pm;h=424c9eec481460ff406fff26256a33d077210775;hb=0c11ad0ee5c8407f6b87d6e15c62a1b445076dc0;hp=bd4687eace2da8fcc845bef41869eb1e7b51d335;hpb=80c2bbe8aa8ce8299baa88270ef930be6e5eecac;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Schema/Versioned.pm b/lib/DBIx/Class/Schema/Versioned.pm index bd4687e..424c9ee 100644 --- a/lib/DBIx/Class/Schema/Versioned.pm +++ b/lib/DBIx/Class/Schema/Versioned.pm @@ -96,10 +96,31 @@ this will attempt to upgrade the database from its current version to the curren schema version using a diff from your I. If a suitable diff is not found then no upgrade is possible. -NB: At the moment, only SQLite and MySQL are supported. This is due to -spotty behaviour in the SQL::Translator producers, please help us by -enhancing them. Ask on the mailing list or IRC channel for details (community details -in L). +=head1 SEE ALSO + +L is a much more powerful alternative to this +module. Examples of things it can do that this module cannot do include + +=over + +=item * + +Downgrades in addition to upgrades + +=item * + +Multiple sql files files per upgrade/downgrade/install + +=item * + +Perl scripts allowed for upgrade/downgrade/install + +=item * + +Just one set of files needed for upgrade, unlike this module where one might +need to generate C + +=back =head1 GETTING STARTED @@ -180,7 +201,7 @@ use strict; use warnings; use base 'DBIx::Class::Schema'; -use Carp::Clan qw/^DBIx::Class/; +use DBIx::Class::Carp; use Time::HiRes qw/gettimeofday/; use Try::Tiny; use namespace::clean; @@ -325,7 +346,7 @@ sub upgrade { # db and schema at same version. do nothing if ( $db_version eq $self->schema_version ) { - carp "Upgrade not necessary\n"; + carp 'Upgrade not necessary'; return; } @@ -396,7 +417,7 @@ sub upgrade_single_step # db and schema at same version. do nothing if ($db_version eq $target_version) { - carp "Upgrade not necessary\n"; + carp 'Upgrade not necessary'; return; } @@ -416,7 +437,7 @@ sub upgrade_single_step $self->create_upgrade_path({ upgrade_file => $upgrade_file }); unless (-f $upgrade_file) { - carp "Upgrade not possible, no upgrade file found ($upgrade_file), please create one\n"; + carp "Upgrade not possible, no upgrade file found ($upgrade_file), please create one"; return; } @@ -578,9 +599,8 @@ sub _on_connect return if ($conn_attrs->{ignore_version} || ($ENV{DBIC_NO_VERSION_CHECK} && !exists $conn_attrs->{ignore_version})); # check for legacy versions table and move to new if exists - my $vschema_compat = DBIx::Class::VersionCompat->connect(@$conn_info); unless ($self->_source_exists($vtable)) { - my $vtable_compat = $vschema_compat->resultset('TableCompat'); + my $vtable_compat = DBIx::Class::VersionCompat->connect(@$conn_info)->resultset('TableCompat'); if ($self->_source_exists($vtable_compat)) { $self->{vschema}->deploy; map { $vtable->create({ installed => $_->Installed, version => $_->Version }) } $vtable_compat->all; @@ -592,18 +612,18 @@ sub _on_connect if($pversion eq $self->schema_version) { -# carp "This version is already installed\n"; + #carp "This version is already installed"; return 1; } if(!$pversion) { - carp "Your DB is currently unversioned. Please call upgrade on your schema to sync the DB.\n"; + carp "Your DB is currently unversioned. Please call upgrade on your schema to sync the DB."; return 1; } carp "Versions out of sync. This is " . $self->schema_version . - ", your database contains version $pversion, please call upgrade on your Schema.\n"; + ", your database contains version $pversion, please call upgrade on your Schema."; } # is this just a waste of time? if not then merge with DBI.pm @@ -664,7 +684,7 @@ sub _create_db_to_schema_diff { print $file $diff; close($file); - carp "WARNING: There may be differences between your DB and your DBIC schema. Please review and if necessary run the SQL in $filename to sync your DB.\n"; + carp "WARNING: There may be differences between your DB and your DBIC schema. Please review and if necessary run the SQL in $filename to sync your DB."; } @@ -699,7 +719,7 @@ sub _set_db_version { $dt[2], $dt[1], $dt[0], - $tm[1] / 1000, # convert to millisecs, format as up/down rounded int above + int($tm[1] / 1000), # convert to millisecs ), }); } @@ -726,18 +746,20 @@ sub _source_exists { my ($self, $rs) = @_; - my $c = try { $rs->search({ 1, 0 })->count }; - - return (defined $c) ? 1 : 0; + return try { + $rs->search(\'1=0')->cursor->next; + 1; + } catch { + 0; + }; } 1; -=head1 AUTHORS +=head1 AUTHOR AND CONTRIBUTORS -Jess Robinson -Luke Saunders +See L and L in DBIx::Class =head1 LICENSE