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