Commit | Line | Data |
600a80a4 |
1 | package DBIx::Class::DeploymentHandler::Cookbook::CustomResultSource; |
2 | |
e80ef6bc |
3 | =pod |
4 | |
5 | One of the reasons for the absurd level of flexibility that |
6 | L<DBIx::Class::DeploymentHandler> is so that you can do things that we did not |
7 | originally anticipate. Surprisingly, I never added a method to change the |
8 | table for the version storage. That's fine though, the following recipe |
9 | shows 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 |
29 | There's not a whole lot special there. The only real bit of code to point out |
30 | is the C<register_class> call. We make sure to point C<__VERSION> to the |
31 | result 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 |
40 | As you can see, this is almost silly how simple it is, we just change the |
41 | table 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 | |
75 | $self->prepare_resultsource_install( |
76 | $self->version_storage->version_rs->result_source |
77 | ); |
78 | } |
79 | |
80 | sub install_version_storage { |
81 | my $self = shift; |
82 | |
83 | $self->install_resultsource( |
84 | $self->version_storage->version_rs->result_source |
85 | ); |
86 | } |
87 | |
88 | sub prepare_install { |
89 | $_[0]->prepare_deploy; |
90 | $_[0]->prepare_version_storage_install; |
91 | } |
92 | |
93 | no Moose; |
94 | __PACKAGE__->meta->make_immutable; |
95 | 1; |
96 | |