add missing newline for no-linenumber-change dzil
[dbsrgits/DBIx-Class-DeploymentHandler.git] / lib / DBIx / Class / DeploymentHandler / HandlesVersioning.pm
CommitLineData
24794769 1package DBIx::Class::DeploymentHandler::HandlesVersioning;
97aa9a74 2
24794769 3use Moose::Role;
4
9deabd1f 5# ABSTRACT: Interface for version methods
6
24794769 7requires 'next_version_set';
f344dd91 8requires 'previous_version_set';
24794769 9
24794769 101;
11
e52174e3 12# vim: ts=2 sw=2 expandtab
13
24794769 14__END__
15
ed1721b9 16=head1 DESCRIPTION
17
d1ae780e 18Typically a VersionHandler will take a C<to_version> and yeild an iterator of
f1d1462a 19L<version sets|/VERSION SET>.
d1ae780e 20
21Typically a call to a VersionHandler's L</next_version_set> with a C<db_version>
22of 1 and a C<to_version> of 5 will iterate over something like the following:
ed1721b9 23
24 [1, 2]
25 [2, 3]
26 [3, 4]
27 [4, 5]
28 undef
29
30or maybe just
31
32 [1, 5]
33 undef
34
f1d1462a 35Really how the L<version sets|/VERSION SET> are arranged is up to the
36VersionHandler being used.
ed1721b9 37
38In some cases users will not want versions to have inherent "previous
39versions," which is why the version set is an C<ArrayRef>. In those cases the
40user should opt to returning merely the version that the database is being
41upgraded to in each step.
42
43One idea that has been suggested to me has been to have a form of dependency
44management of the database "versions." In this case the versions are actually
45more like features that may or may not be applied. For example, one might
46start with version 1 and have a feature (version) C<users>.
47
48Each feature might require that the database be upgraded to another version
49first. If one were to implement a system like this, here is how the
50VersionHandler's L</next_version_set> might look.
51
52 to_version = "users", db_version = 1
53 [3]
54 [5]
55 ["users"]
56 undef
57
58So what just happened there is that C<users> depends on version 5, which depends
59on version 3, which depends on version 1, which is already installed. To be
60clear, the reason we use single versions instead of version pairs is because
61there is no inherent order for this type of database upgraded.
62
63=head2 Downgrades
64
f1d1462a 65For the typical case downgrades should be easy for users to perform and
66understand. That means that with the first two examples given above we can use
ed1721b9 67the L</previous_version_set> iterator to yeild the following:
68
69
70 db_version = 5, to_version=1
4bfd40dd 71 [5, 4]
72 [4, 3]
73 [3, 2]
74 [2, 1]
ed1721b9 75 undef
76
77or maybe just
78
4bfd40dd 79 [5, 1]
ed1721b9 80 undef
81
82Note that we do not swap the version number order. This allows us to remain
83consistent in our version set abstraction, since a version set really just
84describes a version change, and not necesarily a defined progression.
85
96ef97e5 86=method next_version_set
87
5228a963 88 print 'versions to install: ';
89 while (my $vs = $dh->next_version_set) {
90 print join q(, ), @{$vs}
96ef97e5 91 }
5228a963 92 print qq(\n);
93
f1d1462a 94Return a L<version set|/VERSION SET> describing each version that needs to be
5228a963 95installed to upgrade to C<< $dh->to_version >>.
96ef97e5 96
97=method previous_version_set
98
5228a963 99 print 'versions to uninstall: ';
100 while (my $vs = $dh->previous_version_set) {
101 print join q(, ), @{$vs}
96ef97e5 102 }
5228a963 103 print qq(\n);
104
f1d1462a 105Return a L<version set|/VERSION SET> describing each version that needs to be
5228a963 106"installed" to downgrade to C<< $dh->to_version >>.
96ef97e5 107
f1d1462a 108=head1 VERSION SET
109
110A version set could be defined as:
111
112 subtype 'Version', as 'Str';
113 subtype 'VersionSet', as 'ArrayRef[Str]';
114
115A version set should uniquely identify a migration.
116
ed1721b9 117=head1 KNOWN IMPLEMENTATIONS
118
119=over
120
121=item *
122
123L<DBIx::Class::DeploymentHandler::VersionHandler::Monotonic>
124
125=item *
126
127L<DBIx::Class::DeploymentHandler::VersionHandler::DatabaseToSchemaVersions>
128
129=item *
130
131L<DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions>
132
133=back
134