Port to Moo
[dbsrgits/DBIx-Class-DeploymentHandler.git] / lib / DBIx / Class / DeploymentHandler / VersionHandler / DatabaseToSchemaVersions.pm
CommitLineData
c703d15d 1package DBIx::Class::DeploymentHandler::VersionHandler::DatabaseToSchemaVersions;
a976d6e4 2use Moo;
3use Sub::Quote 'quote_sub';
4use MooX::Types::MooseLike::Base qw(Str Bool);
9deabd1f 5
6# ABSTRACT: Go straight from Database to Schema version
7
24794769 8with 'DBIx::Class::DeploymentHandler::HandlesVersioning';
2440e311 9
b539a216 10has schema_version => (
a976d6e4 11 isa => Str,
b539a216 12 is => 'ro',
13 required => 1,
14);
15
16has database_version => (
a976d6e4 17 isa => Str,
b539a216 18 is => 'ro',
19 required => 1,
20);
21
22has to_version => ( # configuration
a976d6e4 23 is => 'ro',
24 isa => Str,
25 builder => '_build_to_version',
b539a216 26);
27
28sub _build_to_version { $_[0]->schema_version }
29
24794769 30has once => (
31 is => 'rw',
a976d6e4 32 isa => Bool,
33 default => quote_sub(q{undef}),
e70a1600 34);
35
24794769 36sub next_version_set {
37 my $self = shift;
38 return undef
39 if $self->once;
e70a1600 40
24794769 41 $self->once(!$self->once);
42 return undef
fb105cfa 43 if $self->database_version eq $self->to_version;
44 return [$self->database_version, $self->to_version];
e70a1600 45}
46
f344dd91 47sub 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
e70a1600 581;
59
e52174e3 60# vim: ts=2 sw=2 expandtab
61
e70a1600 62__END__
63
ec167a97 64=head1 SEE ALSO
e52174e3 65
ec167a97 66This class is an implementation of
67L<DBIx::Class::DeploymentHandler::HandlesVersioning>. Pretty much all the
68documentation is there.