Add a few missing ABSTRACTs
[dbsrgits/DBIx-Class-DeploymentHandler.git] / lib / DBIx / Class / DeploymentHandler / Cookbook / CustomResultSource.pod
CommitLineData
600a80a4 1package DBIx::Class::DeploymentHandler::Cookbook::CustomResultSource;
2
624e2add 3# ABSTRACT: Customize how your DBICDH versions are stored
440e055f 4
624e2add 5=pod
440e055f 6
7=head1 DESCRIPTION
8
e80ef6bc 9One of the reasons for the absurd level of flexibility that
10L<DBIx::Class::DeploymentHandler> is so that you can do things that we did not
11originally anticipate. Surprisingly, I never added a method to change the
12table for the version storage. That's fine though, the following recipe
13shows how one can do it in style:
14
15=head2 Version Storage
16
17 package MyApp::Schema::DBICDHStorage;
823a39c3 18
19 # the following is necessary for some setups
20 use MyApp::Schema::DBICDHStorageResult;
21
6933f31f 22 use Moose;
23 extends 'DBIx::Class::DeploymentHandler::VersionStorage::Standard';
24
25 sub _build_version_rs {
26 $_[0]->schema->register_class(
27 __VERSION =>
e80ef6bc 28 'MyApp::Schema::DBICDHStorageResult'
6933f31f 29 );
30 $_[0]->schema->resultset('__VERSION')
31 }
32
33 no Moose;
34 __PACKAGE__->meta->make_immutable;
35 1;
36
e80ef6bc 37There's not a whole lot special there. The only real bit of code to point out
38is the C<register_class> call. We make sure to point C<__VERSION> to the
39result class that we will define next.
40
41=head2 Version Result Class
42
43 package MyApp::Schema::DBICDHStorageResult;
6933f31f 44 use parent 'DBIx::Class::DeploymentHandler::VersionStorage::Standard::VersionResult';
45 __PACKAGE__->table('fl_bench_journal_versions');
46 1;
47
e80ef6bc 48As you can see, this is almost silly how simple it is, we just change the
49table being set on the original result.
50
51=head2 Our very own DeploymentHandler
52
53 package MyApp::Schema::DeploymentHandler;
6933f31f 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'],
91adde75 64 attributes_to_copy => [qw( databases script_directory sql_translator_args )],
6933f31f 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',
e80ef6bc 74 class_name => 'MyApp::Schema::DBICDHStorage',
6933f31f 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
8bb2f1ac 83 $self->prepare_resultsource_install({
84 result_source => $self->version_storage->version_rs->result_source
85 });
6933f31f 86 }
87
88 sub install_version_storage {
89 my $self = shift;
90
8bb2f1ac 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 });
6933f31f 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
3d416c8f 107Note: if you are using decimal numbers for versioning, you should ammend
108this DeploymentHandler package, setting it's VersionHandler class_name from
109Monotonic ( which handles integer only version numbers ) to ExplicitVersions
110or DatabaseToSchemaVersions, as these handle version numbers as strings
111instead of integers.
112