1 package DBIx::Class::DeploymentHandler;
3 # ABSTRACT: Extensible DBIx::Class deployment
7 extends 'DBIx::Class::DeploymentHandler::Dad';
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
10 with 'DBIx::Class::DeploymentHandler::WithApplicatorDumple' => {
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 => [qw(schema schema_version)],
15 attributes_to_copy => [qw( databases script_directory sql_translator_args )],
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 )],
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'],
29 with 'DBIx::Class::DeploymentHandler::WithReasonableDefaults';
31 sub prepare_version_storage_install {
34 $self->prepare_resultsource_install(
35 $self->version_storage->version_rs->result_source
39 sub install_version_storage {
42 $self->install_resultsource(
43 $self->version_storage->version_rs->result_source
48 $_[0]->prepare_deploy;
49 $_[0]->prepare_version_storage_install;
52 # the following is just a hack so that ->version_storage
54 sub BUILD { $_[0]->version_storage }
55 __PACKAGE__->meta->make_immutable;
59 #vim: ts=2 sw=2 expandtab
65 use aliased 'DBIx::Class::DeploymentHandler' => 'DH';
66 my $s = My::Schema->connect(...);
70 databases => 'SQLite',
71 sql_translator_args => { add_drop_table => 0 },
80 use aliased 'DBIx::Class::DeploymentHandler' => 'DH';
81 my $s = My::Schema->connect(...);
85 databases => 'SQLite',
86 sql_translator_args => { add_drop_table => 0 },
89 $dh->prepare_upgrade(1, 2);
95 C<DBIx::Class::DeploymentHandler> is, as it's name suggests, a tool for
96 deploying and upgrading databases with L<DBIx::Class>. It is designed to be
97 much more flexible than L<DBIx::Class::Schema::Versioned>, hence the use of
98 L<Moose> and lots of roles.
100 C<DBIx::Class::DeploymentHandler> itself is just a recommended set of roles
101 that we think will not only work well for everyone, but will also yeild the
102 best overall mileage. Each role it uses has it's own nuances and
103 documentation, so I won't describe all of them here, but here are a few of the
104 major benefits over how L<DBIx::Class::Schema::Versioned> worked (and
105 L<DBIx::Class::DeploymentHandler::Deprecated> tries to maintain compatibility
112 Downgrades in addition to upgrades.
116 Multiple sql files files per upgrade/downgrade/install.
120 Perl scripts allowed for upgrade/downgrade/install.
124 Just one set of files needed for upgrade, unlike before where one might need
125 to generate C<factorial(scalar @versions)>, which is just silly.
133 That's really just a taste of some of the differences. Check out each role for
136 =head1 WHERE IS ALL THE DOC?!
138 C<DBIx::Class::DeploymentHandler> extends
139 L<DBIx::Class::DeploymentHandler::Dad>, so that's probably the first place to
140 look when you are trying to figure out how everything works.
142 Next would be to look at all the pieces that fill in the blanks that
143 L<DBIx::Class::DeploymentHandler::Dad> expects to be filled. They would be
144 L<DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator>,
145 L<DBIx::Class::DeploymentHandler::VersionHandler::Monotonic>,
146 L<DBIx::Class::DeploymentHandler::VersionStorage::Standard>, and
147 L<DBIx::Class::DeploymentHandler::WithReasonableDefaults>.
149 =method prepare_version_storage_install
151 $dh->prepare_version_storage_install
153 Creates the needed C<.sql> file to install the version storage and not the rest
156 =method prepare_install
160 First prepare all the tables to be installed and the prepare just the version
163 =method install_version_storage
165 $dh->install_version_storage
167 Install the version storage and not the rest of the tables
171 You started your project and weren't using C<DBIx::Class::DeploymentHandler>?
172 Lucky for you I had you in mind when I wrote this doc.
174 First off, you'll want to just install the C<version_storage>:
176 my $s = My::Schema->connect(...);
177 my $dh = DBIx::Class::DeploymentHandler->({ schema => $s });
179 $dh->prepare_version_storage_install;
180 $dh->install_version_storage;
182 Then set your database version:
184 $dh->add_database_version({ version => $s->version });
186 Now you should be able to use C<DBIx::Class::DeploymentHandler> like normal!
190 This is a complex tool, and because of that sometimes you'll want to see
191 what exactly is happening. The best way to do that is to use the built
192 in logging functionality. Currently three of the standard five log levels
193 are used; C<info>, C<debug>, and C<trace>. Info will typically just print
194 out when methods that actually change things along with the most important
195 args to the method. Debug will give you a little bit more information,
196 for example debug will currently tell you which files are being run when
197 a migration is being called. Trace of course goes even further. It will
198 actually give you the SQL or Perl code being executed when a migration is run.
200 To enable the various logging levels all you need to do is set some environment
201 variables: C<DBICDH_INFO>, C<DBICDH_DEBUG>, and C<DBICDH_TRACE>. Each level
202 can be set on it's own, so you can turn on trace without turning on info.
204 Lastly, the logging uses L<Log::Contextual>, so if you have already set up an
205 application-wide logger this will use that logger instead, and the environment
206 variables will be completely ignored (unless you did something weird like
207 set your logger to log when the above environment variables are set.)
211 If you'd like to thank me for the work I've done on this module, don't give me
212 a donation. I spend a lot of free time creating free software, but I do it
215 Instead, consider donating to someone who might actually need it. Obviously
216 you should do research when donating to a charity, so don't just take my word
217 on this. I like Children's Survival Fund:
218 L<http://www.childrenssurvivalfund.org>, but there are a host of other
219 charities that can do much more good than I will with your money.