disallow undef in versions
[dbsrgits/DBIx-Class-DeploymentHandler.git] / lib / DBIx / Class / DeploymentHandler / VersionHandler / DatabaseToSchemaVersions.pm
1 package DBIx::Class::DeploymentHandler::VersionHandler::DatabaseToSchemaVersions;
2 use Moose;
3
4 # ABSTRACT: Go straight from Database to Schema version
5
6 use Method::Signatures::Simple;
7
8 with 'DBIx::Class::DeploymentHandler::HandlesVersioning';
9
10 has schema_version => (
11   isa      => 'Str',
12   is       => 'ro',
13   required => 1,
14 );
15
16 has database_version => (
17   isa      => 'Str',
18   is       => 'ro',
19   required => 1,
20 );
21
22 has to_version => ( # configuration
23   is         => 'ro',
24   isa        => 'Str',
25   lazy_build => 1,
26 );
27
28 sub _build_to_version { $_[0]->schema_version }
29
30 has once => (
31   is      => 'rw',
32   isa     => 'Bool',
33   default => undef,
34 );
35
36 sub next_version_set {
37   my $self = shift;
38   return undef
39     if $self->once;
40
41   $self->once(!$self->once);
42   return undef
43     if $self->database_version eq $self->to_version;
44   return [$self->database_version, $self->to_version];
45 }
46
47 sub previous_version_set {
48   my $self = shift;
49   return undef
50     if $self->once;
51
52   $self->once(!$self->once);
53   return undef
54     if $self->database_version eq $self->to_version;
55   return [$self->database_version, $self->to_version];
56 }
57
58
59 __PACKAGE__->meta->make_immutable;
60
61 1;
62
63 # vim: ts=2 sw=2 expandtab
64
65 __END__
66
67