1 package DBIx::Class::DeploymentHandler::Dad;
4 use Method::Signatures::Simple;
5 require DBIx::Class::Schema; # loaded for type constraint
6 use Carp::Clan '^DBIx::Class::DeploymentHandler';
9 isa => 'DBIx::Class::Schema',
12 handles => ['schema_version'],
15 has backup_directory => (
18 predicate => 'has_backup_directory',
26 sub _build_to_version { $_[0]->schema->schema_version }
29 croak 'Install not possible as versions table already exists in database'
30 if $self->version_storage_is_installed;
32 my $ddl = $self->deploy;
34 $self->add_database_version({
35 version => $self->to_version,
42 while ( my $version_list = $self->next_version_set ) {
43 my ($ddl, $upgrade_sql) = @{$self->upgrade_single_step($version_list)||[]};
45 $self->add_database_version({
46 version => $version_list->[-1],
48 upgrade_sql => $upgrade_sql,
55 while ( my $version_list = $self->previous_version_set ) {
56 $self->downgrade_single_step($version_list);
58 # do we just delete a row here? I think so but not sure
59 $self->delete_database_version({ version => $version_list->[-1] });
63 method backup { $self->storage->backup($self->backup_directory) }
65 __PACKAGE__->meta->make_immutable;
69 # vim: ts=2 sw=2 expandtab
77 The L<DBIx::Class::Schema> (B<required>) that is used to talk to the database
80 =attr backup_directory
82 The directory that backups are stored in
86 The version (defaults to schema's version) to migrate the database to
92 Deploys the current schema into the database. Populates C<version_storage> with
93 C<version> and C<ddl>.
95 B<Note>: you typically need to call C<< $dh->prepare_install >> before you call
98 B<Note>: you cannot install on top of an already installed database
104 Upgrades the database one step at a time till L</next_version_set>
105 returns C<undef>. Each upgrade step will add a C<version>, C<ddl>, and
106 C<upgrade_sql> to the version storage (if C<ddl> and/or C<upgrade_sql> are
107 returned from L</upgrade_single_step>.
113 Downgrades the database one step at a time till L</previous_version_set>
114 returns C<undef>. Each downgrade step will delete a C<version> from the
121 Simply calls backup on the C<< $schema->storage >>, passing in
122 C<< $self->backup_directory >> as an argument. Please test yourself before
123 assuming it will work.
125 =head1 METHODS THAT ARE REQUIRED IN SUBCLASSES
129 See L<DBIx::Class::DeploymentHandler::HandlesDeploy/deploy>.
131 =head2 version_storage_is_installed
133 See L<DBIx::Class::DeploymentHandler::HandlesVersionStorage/version_storage_is_installed>.
135 =head2 add_database_version
137 See L<DBIx::Class::DeploymentHandler::HandlesVersionStorage/add_database_version>.
139 =head2 delete_database_version
141 See L<DBIx::Class::DeploymentHandler::HandlesVersionStorage/delete_database_version>.
143 =head2 next_version_set
145 See L<DBIx::Class::DeploymentHandler::HandlesVersioning/next_version_set>.
147 =head2 previous_version_set
149 See L<DBIx::Class::DeploymentHandler::HandlesVersioning/previous_version_set>.
151 =head2 upgrade_single_step
153 See L<DBIx::Class::DeploymentHandler::HandlesDeploy/upgrade_single_step>.
155 =head2 downgrade_single_step
157 See L<DBIx::Class::DeploymentHandler::HandlesDeploy/downgrade_single_step>.
159 =head1 ORTHODOX METHODS
161 These methods are not actually B<required> as things will probably still work
162 if you don't implement them, but if you want your subclass to get along with
163 other subclasses (or more likely, tools made to use another subclass), you
164 should probably implement these too, even if they are no-ops.
166 =head2 database_version
168 see L<DBIx::Class::DeploymentHandler::HandlesVersionStorage/database_version>
170 =head2 prepare_install
172 see L<DBIx::Class::DeploymentHandler::HandlesDeploy/prepare_install>
174 =head2 prepare_resultsource_install
176 see L<DBIx::Class::DeploymentHandler::HandlesDeploy/prepare_resultsource_install>
178 =head2 install_resultsource
180 see L<DBIx::Class::DeploymentHandler::HandlesDeploy/install_resultsource>
182 =head2 prepare_upgrade
184 see L<DBIx::Class::DeploymentHandler::HandlesDeploy/prepare_upgrade>
186 =head2 prepare_downgrade
188 see L<DBIx::Class::DeploymentHandler::HandlesDeploy/prepare_downgrade>
194 All of the methods mentioned in L</METHODS THAT ARE REQUIRED IN SUBCLASSES> and
195 L</ORTHODOX METHODS> can be implemented in any fashion you choose. In the
196 spirit of code reuse I have used roles to implement them in my two subclasses,
197 L<DBIx::Class::DeploymentHandler> and
198 L<DBIx::Class::DeploymentHandler::Deprecated>, but you are free to implement
199 them entirely in a subclass if you so choose to.
201 For in-depth documentation on how methods are supposed to work, see the roles
202 L<DBIx::Class::DeploymentHandler::HandlesDeploy>,
203 L<DBIx::Class::DeploymentHandler::HandlesVersioning>, and
204 L<DBIx::Class::DeploymentHandler::HandlesVersionStorage>.