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 => (
32 has _index_of_versions => (
38 sub _build__index_of_versions {
41 for (@{ $_[0]->ordered_versions }) {
53 sub _build__version_idx { $_[0]->_index_of_versions->{$_[0]->database_version} }
55 sub _inc_version_idx { $_[0]->_version_idx($_[0]->_version_idx + 1 ) }
56 sub _dec_version_idx { $_[0]->_version_idx($_[0]->_version_idx - 1 ) }
59 sub next_version_set {
62 $self->_index_of_versions->{$self->to_version} <
65 croak "you are trying to upgrade and your current version is greater\n".
66 "than the version you are trying to upgrade to. Either downgrade\n".
67 "or update your schema"
68 } elsif ( $self->_version_idx == $self->_index_of_versions->{$self->to_version}) {
71 my $next_idx = $self->_inc_version_idx;
73 $self->ordered_versions->[$next_idx - 1],
74 $self->ordered_versions->[$next_idx ],
79 sub previous_version_set {
82 $self->_index_of_versions->{$self->to_version} >
85 croak "you are trying to downgrade and your current version is less\n".
86 "than the version you are trying to downgrade to. Either upgrade\n".
87 "or update your schema"
88 } elsif ( $self->_version_idx == $self->_index_of_versions->{$self->to_version}) {
91 my $next_idx = $self->_dec_version_idx;
93 $self->ordered_versions->[$next_idx ],
94 $self->ordered_versions->[$next_idx + 1],
99 __PACKAGE__->meta->make_immutable;
105 vim: ts=2 sw=2 expandtab