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 => (
27 sub _build_to_version { $_[0]->schema_version }
29 has ordered_versions => (
35 has _index_of_versions => (
41 sub _build__index_of_versions {
44 for (@{ $_[0]->ordered_versions }) {
56 sub _build__version_idx { $_[0]->_index_of_versions->{$_[0]->database_version} }
58 sub _inc_version_idx { $_[0]->_version_idx($_[0]->_version_idx + 1 ) }
59 sub _dec_version_idx { $_[0]->_version_idx($_[0]->_version_idx - 1 ) }
62 sub next_version_set {
65 $self->_index_of_versions->{$self->to_version} <
68 croak "you are trying to upgrade and your current version is greater\n".
69 "than the version you are trying to upgrade to. Either downgrade\n".
70 "or update your schema"
71 } elsif ( $self->_version_idx == $self->_index_of_versions->{$self->to_version}) {
74 my $next_idx = $self->_inc_version_idx;
76 $self->ordered_versions->[$next_idx - 1],
77 $self->ordered_versions->[$next_idx ],
82 sub previous_version_set {
85 $self->_index_of_versions->{$self->to_version} >
88 croak "you are trying to downgrade and your current version is less\n".
89 "than the version you are trying to downgrade to. Either upgrade\n".
90 "or update your schema"
91 } elsif ( $self->_version_idx == $self->_index_of_versions->{$self->to_version}) {
94 my $next_idx = $self->_dec_version_idx;
96 $self->ordered_versions->[$next_idx ],
97 $self->ordered_versions->[$next_idx + 1],
102 __PACKAGE__->meta->make_immutable;
106 # vim: ts=2 sw=2 expandtab