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