Add a few missing ABSTRACTs
[dbsrgits/DBIx-Class-DeploymentHandler.git] / lib / DBIx / Class / DeploymentHandler / Cookbook / CustomResultSource.pod
1 package DBIx::Class::DeploymentHandler::Cookbook::CustomResultSource;
2
3 # ABSTRACT: Customize how your DBICDH versions are stored
4
5 =pod
6
7 =head1 DESCRIPTION
8
9 One of the reasons for the absurd level of flexibility that
10 L<DBIx::Class::DeploymentHandler> is so that you can do things that we did not
11 originally anticipate.  Surprisingly, I never added a method to change the
12 table for the version storage.  That's fine though, the following recipe
13 shows how one can do it in style:
14
15 =head2 Version Storage
16
17  package MyApp::Schema::DBICDHStorage;
18  
19  # the following is necessary for some setups
20  use MyApp::Schema::DBICDHStorageResult;
21  
22  use Moose;
23  extends 'DBIx::Class::DeploymentHandler::VersionStorage::Standard';
24
25  sub _build_version_rs {
26    $_[0]->schema->register_class(
27      __VERSION =>
28        'MyApp::Schema::DBICDHStorageResult'
29    );
30    $_[0]->schema->resultset('__VERSION')
31  }
32
33  no Moose;
34  __PACKAGE__->meta->make_immutable;
35  1;
36
37 There's not a whole lot special there.  The only real bit of code to point out
38 is the C<register_class> call.  We make sure to point C<__VERSION> to the
39 result class that we will define next.
40
41 =head2 Version Result Class
42
43  package MyApp::Schema::DBICDHStorageResult;
44  use parent 'DBIx::Class::DeploymentHandler::VersionStorage::Standard::VersionResult';
45  __PACKAGE__->table('fl_bench_journal_versions');
46  1;
47
48 As you can see, this is almost silly how simple it is, we just change the
49 table being set on the original result.
50
51 =head2 Our very own DeploymentHandler
52
53  package MyApp::Schema::DeploymentHandler;
54  use Moose;
55  extends 'DBIx::Class::DeploymentHandler::Dad';
56
57  # a single with would be better, but we can't do that
58  # see: http://rt.cpan.org/Public/Bug/Display.html?id=46347
59  with 'DBIx::Class::DeploymentHandler::WithApplicatorDumple' => {
60      interface_role       => 'DBIx::Class::DeploymentHandler::HandlesDeploy',
61      class_name           => 'DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator',
62      delegate_name        => 'deploy_method',
63      attributes_to_assume => ['schema'],
64      attributes_to_copy   => [qw( databases script_directory sql_translator_args )],
65    },
66    'DBIx::Class::DeploymentHandler::WithApplicatorDumple' => {
67      interface_role       => 'DBIx::Class::DeploymentHandler::HandlesVersioning',
68      class_name           => 'DBIx::Class::DeploymentHandler::VersionHandler::Monotonic',
69      delegate_name        => 'version_handler',
70      attributes_to_assume => [qw( database_version schema_version to_version )],
71    },
72    'DBIx::Class::DeploymentHandler::WithApplicatorDumple' => {
73      interface_role       => 'DBIx::Class::DeploymentHandler::HandlesVersionStorage',
74      class_name           => 'MyApp::Schema::DBICDHStorage',
75      delegate_name        => 'version_storage',
76      attributes_to_assume => ['schema'],
77    };
78  with 'DBIx::Class::DeploymentHandler::WithReasonableDefaults';
79
80  sub prepare_version_storage_install {
81    my $self = shift;
82
83    $self->prepare_resultsource_install({
84        result_source => $self->version_storage->version_rs->result_source
85    });
86  }
87
88  sub install_version_storage {
89    my $self = shift;
90
91    my $version = (shift || {})->{version} || $self->schema_version;
92    $self->install_resultsource({
93        result_source => $self->version_storage->version_rs->result_source,
94        version       => $version,
95    });
96  }
97
98  sub prepare_install {
99     $_[0]->prepare_deploy;
100     $_[0]->prepare_version_storage_install;
101  }
102
103  no Moose;
104  __PACKAGE__->meta->make_immutable;
105  1;
106
107 Note: if you are using decimal numbers for versioning, you should ammend
108 this DeploymentHandler package, setting it's VersionHandler class_name from
109 Monotonic ( which handles integer only version numbers ) to ExplicitVersions
110 or DatabaseToSchemaVersions, as these handle version numbers as strings
111 instead of integers.
112