fix VersionResult to actually work
[dbsrgits/DBIx-Class-DeploymentHandler.git] / lib / DBIx / Class / DeploymentHandler / Component.pm
1 package DBIx::Class::DeploymentHandler::Component;
2
3 use strict;
4 use warnings;
5
6 use Carp 'carp';
7 use DBIx::Class::DeploymentHandler::VersionResult;
8
9 sub set_us_up_the_bomb {
10         my $self = shift;
11
12         $self->register_class(
13                 __VERSION => 'DBIx::Class::DeploymentHandler::VersionResult'
14         );
15 }
16
17 sub connection  {
18   my $self = shift;
19   $self->next::method(@_);
20
21   $self->set_us_up_the_bomb;
22
23   my $args = $_[3] || {};
24
25   return if $args->{ignore_version} || $ENV{DBIC_NO_VERSION_CHECK};
26
27   my $versions = $self->resultset('__VERSION');
28
29   unless($versions->is_installed) {
30           carp "Your DB is currently unversioned. Please call upgrade on your schema to sync the DB.\n";
31           return $self;
32   }
33
34   my $pversion = $versions->db_version;
35
36   return $self if $pversion eq $self->schema_version;
37
38   carp "Versions out of sync. This is " . $self->schema_version .
39     ", your database contains version $pversion, please call upgrade on your Schema.\n";
40
41   return $self;
42 }
43
44 1;