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