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