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