1DBIx::Class::DeploymentUHsaenrdlCeorn(t3r)ibuted Perl DoDcBuImxe:n:tCaltaisosn::DeploymentHandler(3)
2
3
4
6 DBIx::Class::DeploymentHandler - Extensible DBIx::Class deployment
7
9 use aliased 'DBIx::Class::DeploymentHandler' => 'DH';
10 my $s = My::Schema->connect(...);
11
12 my $dh = DH->new({
13 schema => $s,
14 databases => 'SQLite',
15 sql_translator_args => { add_drop_table => 0 },
16 });
17
18 $dh->prepare_install;
19
20 $dh->install;
21
22 or for upgrades:
23
24 use aliased 'DBIx::Class::DeploymentHandler' => 'DH';
25 my $s = My::Schema->connect(...);
26
27 my $dh = DH->new({
28 schema => $s,
29 databases => 'SQLite',
30 sql_translator_args => { add_drop_table => 0 },
31 });
32
33 $dh->prepare_deploy;
34 $dh->prepare_upgrade({
35 from_version => 1,
36 to_version => 2,
37 });
38
39 $dh->upgrade;
40
42 "DBIx::Class::DeploymentHandler" is, as its name suggests, a tool for
43 deploying and upgrading databases with DBIx::Class. It is designed to
44 be much more flexible than DBIx::Class::Schema::Versioned, hence the
45 use of Moose and lots of roles.
46
47 "DBIx::Class::DeploymentHandler" itself is just a recommended set of
48 roles that we think will not only work well for everyone, but will also
49 yield the best overall mileage. Each role it uses has its own nuances
50 and documentation, so I won't describe all of them here, but here are a
51 few of the major benefits over how DBIx::Class::Schema::Versioned
52 worked (and DBIx::Class::DeploymentHandler::Deprecated tries to
53 maintain compatibility with):
54
55 · Downgrades in addition to upgrades.
56
57 · Multiple sql files files per upgrade/downgrade/install.
58
59 · Perl scripts allowed for upgrade/downgrade/install.
60
61 · Just one set of files needed for upgrade, unlike before where one
62 might need to generate "factorial(scalar @versions)", which is just
63 silly.
64
65 · And much, much more!
66
67 That's really just a taste of some of the differences. Check out each
68 role for all the details.
69
71 To get up and running fast, your best place to start is
72 DBIx::Class::DeploymentHandler::Manual::Intro and then
73 DBIx::Class::DeploymentHandler::Manual::CatalystIntro if your intending
74 on using this with Catalyst.
75
76 For the full story you should realise that
77 "DBIx::Class::DeploymentHandler" extends
78 DBIx::Class::DeploymentHandler::Dad, so that's probably the first place
79 to look when you are trying to figure out how everything works.
80
81 Next would be to look at all the pieces that fill in the blanks that
82 DBIx::Class::DeploymentHandler::Dad expects to be filled. They would
83 be DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator,
84 DBIx::Class::DeploymentHandler::VersionHandler::Monotonic,
85 DBIx::Class::DeploymentHandler::VersionStorage::Standard, and
86 DBIx::Class::DeploymentHandler::WithReasonableDefaults.
87
89 "DBIx::Class::DeploymentHandler" has a strange structure. The gist is
90 that it delegates to three small objects that are proxied to via
91 interface roles that then create the illusion of one large, monolithic
92 object. Here is a diagram that might help:
93
94 The nice thing about this is that we have well defined interfaces for
95 the objects that comprise the "DeploymentHandler", the smaller objects
96 can be tested in isolation, and the smaller objects can even be swapped
97 in easily. But the real win is that you can subclass the
98 "DeploymentHandler" without knowing about the underlying delegation;
99 you just treat it like normal Perl and write methods that do what you
100 want.
101
103 You started your project and weren't using
104 "DBIx::Class::DeploymentHandler"? Lucky for you I had you in mind when
105 I wrote this doc.
106
107 First, define the version in your main schema file (maybe using
108 $VERSION).
109
110 Then you'll want to just install the version_storage:
111
112 my $s = My::Schema->connect(...);
113 my $dh = DBIx::Class::DeploymentHandler->new({ schema => $s });
114
115 $dh->prepare_version_storage_install;
116 $dh->install_version_storage;
117
118 Then set your database version:
119
120 $dh->add_database_version({ version => $s->schema_version });
121
122 Now you should be able to use "DBIx::Class::DeploymentHandler" like
123 normal!
124
126 This is a complex tool, and because of that sometimes you'll want to
127 see what exactly is happening. The best way to do that is to use the
128 built in logging functionality. It the standard six log levels;
129 "fatal", "error", "warn", "info", "debug", and "trace". Most of those
130 are pretty self explanatory. Generally a safe level to see what all is
131 going on is debug, which will give you everything except for the exact
132 SQL being run.
133
134 To enable the various logging levels all you need to do is set an
135 environment variables: "DBICDH_FATAL", "DBICDH_ERROR", "DBICDH_WARN",
136 "DBICDH_INFO", "DBICDH_DEBUG", and "DBICDH_TRACE". Each level can be
137 set on its own, but the default is the first three on and the last
138 three off, and the levels cascade, so if you turn on trace the rest
139 will turn on automatically.
140
142 If you'd like to thank me for the work I've done on this module, don't
143 give me a donation. I spend a lot of free time creating free software,
144 but I do it because I love it.
145
146 Instead, consider donating to someone who might actually need it.
147 Obviously you should do research when donating to a charity, so don't
148 just take my word on this. I like Matthew 25: Ministries:
149 <http://www.m25m.org/>, but there are a host of other charities that
150 can do much more good than I will with your money. (Third party
151 charity info here:
152 <http://www.charitynavigator.org/index.cfm?bay=search.summary&orgid=6901>
153
155 prepare_version_storage_install
156 $dh->prepare_version_storage_install
157
158 Creates the needed ".sql" file to install the version storage and not
159 the rest of the tables
160
161 prepare_install
162 $dh->prepare_install
163
164 First prepare all the tables to be installed and the prepare just the
165 version storage
166
167 install_version_storage
168 $dh->install_version_storage
169
170 Install the version storage and not the rest of the tables
171
173 Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
174
176 This software is copyright (c) 2018 by Arthur Axel "fREW" Schmidt.
177
178 This is free software; you can redistribute it and/or modify it under
179 the same terms as the Perl 5 programming language system itself.
180
181
182
183perl v5.28.1 2018-01-06 DBIx::Class::DeploymentHandler(3)