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