1 package DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions;
5 with 'DBIx::Class::DeploymentHandler::HandlesVersioning';
7 has schema_version => (
13 has database_version => (
24 sub _build_to_version { $_[0]->schema_version }
26 has ordered_versions => (
31 my $to_version = $_[0]->to_version;
32 my $db_version = $_[0]->database_version;
34 croak 'to_version not in ordered_versions'
35 unless grep { $to_version eq $_ } @{ $_[1] };
37 croak 'database_version not in ordered_versions'
38 unless grep { $db_version eq $_ } @{ $_[1] };
41 return if $_ eq $db_version;
42 croak 'to_version is before database version in ordered_versions'
54 sub _inc_version_idx { $_[0]->_version_idx($_[0]->_version_idx + 1 ) }
55 sub _dec_version_idx { $_[0]->_version_idx($_[0]->_version_idx - 1 ) }
57 sub _build__version_idx {
59 my $start = $self->database_version;
61 for (@{$self->ordered_versions}) {
63 if $_ eq $self->database_version;
68 sub next_version_set {
71 if $self->ordered_versions->[$self->_version_idx] eq $self->to_version;
73 # this should never get in infinite loops because we ensure
74 # that the database version is in the list in the version_idx
76 my $next_idx = $self->_inc_version_idx;
78 $self->ordered_versions->[$next_idx - 1],
79 $self->ordered_versions->[$next_idx ],
83 sub previous_version_set {
86 if $self->ordered_versions->[$self->_version_idx] eq $self->database_version;
88 # this should never get in infinite loops because we ensure
89 # that the database version is in the list in the version_idx
91 my $next_idx = $self->_dec_version_idx;
93 $self->ordered_versions->[$next_idx - 1],
94 $self->ordered_versions->[$next_idx ],
98 __PACKAGE__->meta->make_immutable;
104 vim: ts=2 sw=2 expandtab