1 package DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions;
4 # ABSTRACT: Define your own list of versions to use for migrations
8 with 'DBIx::Class::DeploymentHandler::HandlesVersioning';
10 has schema_version => (
16 has database_version => (
28 sub _build_to_version { $_[0]->schema_version }
30 has ordered_versions => (
36 has _index_of_versions => (
42 sub _build__index_of_versions {
45 for (@{ $_[0]->ordered_versions }) {
57 sub _build__version_idx { $_[0]->_index_of_versions->{$_[0]->database_version} }
59 sub _inc_version_idx { $_[0]->_version_idx($_[0]->_version_idx + 1 ) }
60 sub _dec_version_idx { $_[0]->_version_idx($_[0]->_version_idx - 1 ) }
63 sub next_version_set {
66 $self->_index_of_versions->{$self->to_version} <
69 croak "you are trying to upgrade and your current version is greater\n".
70 "than the version you are trying to upgrade to. Either downgrade\n".
71 "or update your schema"
72 } elsif ( $self->_version_idx == $self->_index_of_versions->{$self->to_version}) {
75 my $next_idx = $self->_inc_version_idx;
77 $self->ordered_versions->[$next_idx - 1],
78 $self->ordered_versions->[$next_idx ],
83 sub previous_version_set {
86 $self->_index_of_versions->{$self->to_version} >
89 croak "you are trying to downgrade and your current version is less\n".
90 "than the version you are trying to downgrade to. Either upgrade\n".
91 "or update your schema"
92 } elsif ( $self->_version_idx == $self->_index_of_versions->{$self->to_version}) {
95 my $next_idx = $self->_dec_version_idx;
97 $self->ordered_versions->[$next_idx + 1],
98 $self->ordered_versions->[$next_idx ],
103 __PACKAGE__->meta->make_immutable;
107 # vim: ts=2 sw=2 expandtab