add MXRP to deps
[dbsrgits/DBIx-Class-DeploymentHandler.git] / lib / DBIx / Class / DeploymentHandler.pm
CommitLineData
b974984a 1package DBIx::Class::DeploymentHandler;
2
a65184c8 3# ABSTRACT: Extensible DBIx::Class deployment
4
b974984a 5use Moose;
b974984a 6
c4f4d4a2 7extends 'DBIx::Class::DeploymentHandler::Dad';
41219a5d 8# a single with would be better, but we can't do that
9# see: http://rt.cpan.org/Public/Bug/Display.html?id=46347
4f73e4ac 10with 'DBIx::Class::DeploymentHandler::WithApplicatorDumple' => {
36009fc8 11 interface_role => 'DBIx::Class::DeploymentHandler::HandlesDeploy',
12 class_name => 'DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator',
13 delegate_name => 'deploy_method',
14 attributes_to_assume => ['schema'],
15 attributes_to_copy => [qw( databases upgrade_directory sql_translator_args )],
16 },
17 'DBIx::Class::DeploymentHandler::WithApplicatorDumple' => {
18 interface_role => 'DBIx::Class::DeploymentHandler::HandlesVersioning',
19 class_name => 'DBIx::Class::DeploymentHandler::VersionHandler::Monotonic',
20 delegate_name => 'version_handler',
21 attributes_to_assume => [qw( database_version schema_version to_version )],
22 },
23 'DBIx::Class::DeploymentHandler::WithApplicatorDumple' => {
24 interface_role => 'DBIx::Class::DeploymentHandler::HandlesVersionStorage',
25 class_name => 'DBIx::Class::DeploymentHandler::VersionStorage::Standard',
26 delegate_name => 'version_storage',
27 attributes_to_assume => ['schema'],
28 };
41219a5d 29with 'DBIx::Class::DeploymentHandler::WithReasonableDefaults';
2e68a8e1 30
c8a2f7bd 31sub prepare_version_storage_install {
32 my $self = shift;
33
34 $self->prepare_resultsource_install(
35 $self->version_storage->version_rs->result_source
36 );
37}
38
39sub install_version_storage {
40 my $self = shift;
41
42 $self->install_resultsource(
43 $self->version_storage->version_rs->result_source
44 );
45}
46
d794b8ce 47sub prepare_install {
36821446 48 $_[0]->prepare_deploy;
49 $_[0]->prepare_version_storage_install;
d794b8ce 50}
51
2e68a8e1 52__PACKAGE__->meta->make_immutable;
53
b974984a 541;
61847972 55
d1ae780e 56#vim: ts=2 sw=2 expandtab
57
58__END__
59
a65184c8 60=head1 SYNOPSIS
e9c19a98 61
62 use aliased 'DBIx::Class::DeploymentHandler' => 'DH';
63 my $s = My::Schema->connect(...);
64
65 my $dh = DH->new({
02a7b8ac 66 schema => $s,
67 databases => 'SQLite',
68 sql_translator_args => { add_drop_table => 0 },
e9c19a98 69 });
70
f7e215c9 71 $dh->prepare_install;
e9c19a98 72
73 $dh->install;
74
75or for upgrades:
76
77 use aliased 'DBIx::Class::DeploymentHandler' => 'DH';
78 my $s = My::Schema->connect(...);
79
80 my $dh = DH->new({
02a7b8ac 81 schema => $s,
82 databases => 'SQLite',
83 sql_translator_args => { add_drop_table => 0 },
e9c19a98 84 });
85
86 $dh->prepare_upgrade(1, 2);
87
88 $dh->upgrade;
89
90=head1 DESCRIPTION
91
92C<DBIx::Class::DeploymentHandler> is, as it's name suggests, a tool for
93deploying and upgrading databases with L<DBIx::Class>. It is designed to be
94much more flexible than L<DBIx::Class::Schema::Versioned>, hence the use of
95L<Moose> and lots of roles.
96
97C<DBIx::Class::DeploymentHandler> itself is just a recommended set of roles
98that we think will not only work well for everyone, but will also yeild the
99best overall mileage. Each role it uses has it's own nuances and
100documentation, so I won't describe all of them here, but here are a few of the
101major benefits over how L<DBIx::Class::Schema::Versioned> worked (and
102L<DBIx::Class::DeploymentHandler::Deprecated> tries to maintain compatibility
103with):
104
105=over
106
e9c19a98 107=item *
108
109Downgrades in addition to upgrades.
110
111=item *
112
113Multiple sql files files per upgrade/downgrade/install.
114
115=item *
116
117Perl scripts allowed for upgrade/downgrade/install.
118
119=item *
120
121Just one set of files needed for upgrade, unlike before where one might need
122to generate C<factorial(scalar @versions)>, which is just silly.
123
124=item *
125
126And much, much more!
127
128=back
129
130That's really just a taste of some of the differences. Check out each role for
131all the details.
132
133=head1 WHERE IS ALL THE DOC?!
134
135C<DBIx::Class::DeploymentHandler> extends
136L<DBIx::Class::DeploymentHandler::Dad>, so that's probably the first place to
137look when you are trying to figure out how everything works.
138
139Next would be to look at all the roles that fill in the blanks that
140L<DBIx::Class::DeploymentHandler::Dad> expects to be filled. They would be
141L<DBIx::Class::DeploymentHandler::WithSqltDeployMethod>,
142L<DBIx::Class::DeploymentHandler::WithMonotonicVersions>,
143L<DBIx::Class::DeploymentHandler::WithStandardVersionStorage>, and
144L<DBIx::Class::DeploymentHandler::WithReasonableDefaults>.
145
146=method prepare_version_storage_install
147
148 $dh->prepare_version_storage_install
149
150Creates the needed C<.sql> file to install the version storage and not the rest
151of the tables
152
f7e215c9 153=method prepare_install
154
155 $dh->prepare_install
156
157First prepare all the tables to be installed and the prepare just the version
158storage
159
e9c19a98 160=method install_version_storage
161
162 $dh->install_version_storage
163
164Install the version storage and not the rest of the tables
165
d1ae780e 166=head1 THIS SUCKS
167
12d6fbad 168You started your project and weren't using C<DBIx::Class::DeploymentHandler>?
169Lucky for you I had you in mind when I wrote this doc.
d1ae780e 170
ee37360d 171First off, you'll want to just install the C<version_storage>:
d1ae780e 172
173 my $s = My::Schema->connect(...);
12d6fbad 174 my $dh = DBIx::Class::DeploymentHandler({ schema => $s });
d1ae780e 175
176 $dh->prepare_version_storage_install;
177 $dh->install_version_storage;
34ac0a51 178
12d6fbad 179Then set your database version:
180
181 $dh->add_database_version({ version => $s->version });
182
ee37360d 183Now you should be able to use C<DBIx::Class::DeploymentHandler> like normal!
698944cb 184
185=head1 DONATIONS
186
187If you'd like to thank me for the work I've done on this module, don't give me
188a donation. I spend a lot of free time creating free software, but I do it
189because I love it.
190
191Instead, consider donating to someone who might actually need it. Obviously
192you should do research when donating to a charity, so don't just take my word
26983cf2 193on this. I like Children's Survival Fund:
194L<http://www.childrenssurvivalfund.org>, but there are a host of other
195charities that can do much more good than I will with your money.