1 package DBIx::Class::DeploymentHandler::Dad;
3 # ABSTRACT: Parent class for DeploymentHandlers
6 use Method::Signatures::Simple;
7 require DBIx::Class::Schema; # loaded for type constraint
8 use Carp::Clan '^DBIx::Class::DeploymentHandler';
11 isa => 'DBIx::Class::Schema',
14 handles => ['schema_version'],
17 has backup_directory => (
20 predicate => 'has_backup_directory',
28 sub _build_to_version { $_[0]->schema->schema_version }
31 croak 'Install not possible as versions table already exists in database'
32 if $self->version_storage_is_installed;
34 my $ddl = $self->deploy;
36 $self->add_database_version({
37 version => $self->to_version,
44 while ( my $version_list = $self->next_version_set ) {
45 my ($ddl, $upgrade_sql) = @{$self->upgrade_single_step($version_list)||[]};
47 $self->add_database_version({
48 version => $version_list->[-1],
50 upgrade_sql => $upgrade_sql,
57 while ( my $version_list = $self->previous_version_set ) {
58 $self->downgrade_single_step($version_list);
60 # do we just delete a row here? I think so but not sure
61 $self->delete_database_version({ version => $version_list->[-1] });
65 method backup { $self->storage->backup($self->backup_directory) }
67 __PACKAGE__->meta->make_immutable;
71 # vim: ts=2 sw=2 expandtab
79 The L<DBIx::Class::Schema> (B<required>) that is used to talk to the database
82 =attr backup_directory
84 The directory that backups are stored in
88 The version (defaults to schema's version) to migrate the database to
94 Deploys the current schema into the database. Populates C<version_storage> with
95 C<version> and C<ddl>.
97 B<Note>: you typically need to call C<< $dh->prepare_install >> before you call
100 B<Note>: you cannot install on top of an already installed database
106 Upgrades the database one step at a time till L</next_version_set>
107 returns C<undef>. Each upgrade step will add a C<version>, C<ddl>, and
108 C<upgrade_sql> to the version storage (if C<ddl> and/or C<upgrade_sql> are
109 returned from L</upgrade_single_step>.
115 Downgrades the database one step at a time till L</previous_version_set>
116 returns C<undef>. Each downgrade step will delete a C<version> from the
123 Simply calls backup on the C<< $schema->storage >>, passing in
124 C<< $self->backup_directory >> as an argument. Please test yourself before
125 assuming it will work.
127 =head1 METHODS THAT ARE REQUIRED IN SUBCLASSES
131 See L<DBIx::Class::DeploymentHandler::HandlesDeploy/deploy>.
133 =head2 version_storage_is_installed
135 See L<DBIx::Class::DeploymentHandler::HandlesVersionStorage/version_storage_is_installed>.
137 =head2 add_database_version
139 See L<DBIx::Class::DeploymentHandler::HandlesVersionStorage/add_database_version>.
141 =head2 delete_database_version
143 See L<DBIx::Class::DeploymentHandler::HandlesVersionStorage/delete_database_version>.
145 =head2 next_version_set
147 See L<DBIx::Class::DeploymentHandler::HandlesVersioning/next_version_set>.
149 =head2 previous_version_set
151 See L<DBIx::Class::DeploymentHandler::HandlesVersioning/previous_version_set>.
153 =head2 upgrade_single_step
155 See L<DBIx::Class::DeploymentHandler::HandlesDeploy/upgrade_single_step>.
157 =head2 downgrade_single_step
159 See L<DBIx::Class::DeploymentHandler::HandlesDeploy/downgrade_single_step>.
161 =head1 ORTHODOX METHODS
163 These methods are not actually B<required> as things will probably still work
164 if you don't implement them, but if you want your subclass to get along with
165 other subclasses (or more likely, tools made to use another subclass), you
166 should probably implement these too, even if they are no-ops.
168 =head2 database_version
170 see L<DBIx::Class::DeploymentHandler::HandlesVersionStorage/database_version>
172 =head2 prepare_install
174 see L<DBIx::Class::DeploymentHandler::HandlesDeploy/prepare_install>
176 =head2 prepare_resultsource_install
178 see L<DBIx::Class::DeploymentHandler::HandlesDeploy/prepare_resultsource_install>
180 =head2 install_resultsource
182 see L<DBIx::Class::DeploymentHandler::HandlesDeploy/install_resultsource>
184 =head2 prepare_upgrade
186 see L<DBIx::Class::DeploymentHandler::HandlesDeploy/prepare_upgrade>
188 =head2 prepare_downgrade
190 see L<DBIx::Class::DeploymentHandler::HandlesDeploy/prepare_downgrade>
196 All of the methods mentioned in L</METHODS THAT ARE REQUIRED IN SUBCLASSES> and
197 L</ORTHODOX METHODS> can be implemented in any fashion you choose. In the
198 spirit of code reuse I have used roles to implement them in my two subclasses,
199 L<DBIx::Class::DeploymentHandler> and
200 L<DBIx::Class::DeploymentHandler::Deprecated>, but you are free to implement
201 them entirely in a subclass if you so choose to.
203 For in-depth documentation on how methods are supposed to work, see the roles
204 L<DBIx::Class::DeploymentHandler::HandlesDeploy>,
205 L<DBIx::Class::DeploymentHandler::HandlesVersioning>, and
206 L<DBIx::Class::DeploymentHandler::HandlesVersionStorage>.