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