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