1 package DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions;
3 use MooX::Types::MooseLike::Base qw(Str ArrayRef Int HashRef);
5 # ABSTRACT: Define your own list of versions to use for migrations
9 with 'DBIx::Class::DeploymentHandler::HandlesVersioning';
11 has schema_version => (
17 has database_version => (
26 builder => '_build_to_version',
30 sub _build_to_version { $_[0]->schema_version }
32 has ordered_versions => (
38 has _index_of_versions => (
41 builder => '_build__index_of_versions',
45 sub _build__index_of_versions {
48 for (@{ $_[0]->ordered_versions }) {
57 builder => '_build__version_idx',
61 sub _build__version_idx { $_[0]->_index_of_versions->{$_[0]->database_version} }
63 sub _inc_version_idx { $_[0]->_version_idx($_[0]->_version_idx + 1 ) }
64 sub _dec_version_idx { $_[0]->_version_idx($_[0]->_version_idx - 1 ) }
67 sub next_version_set {
70 $self->_index_of_versions->{$self->to_version} <
73 croak "you are trying to upgrade and your current version is greater\n".
74 "than the version you are trying to upgrade to. Either downgrade\n".
75 "or update your schema"
76 } elsif ( $self->_version_idx == $self->_index_of_versions->{$self->to_version}) {
79 my $next_idx = $self->_inc_version_idx;
81 $self->ordered_versions->[$next_idx - 1],
82 $self->ordered_versions->[$next_idx ],
87 sub previous_version_set {
90 $self->_index_of_versions->{$self->to_version} >
93 croak "you are trying to downgrade and your current version is less\n".
94 "than the version you are trying to downgrade to. Either upgrade\n".
95 "or update your schema"
96 } elsif ( $self->_version_idx == $self->_index_of_versions->{$self->to_version}) {
99 my $next_idx = $self->_dec_version_idx;
101 $self->ordered_versions->[$next_idx + 1],
102 $self->ordered_versions->[$next_idx ],
109 # vim: ts=2 sw=2 expandtab
115 This class is an implementation of
116 L<DBIx::Class::DeploymentHandler::HandlesVersioning>. Pretty much all the
117 documentation is there.