1 package DBIx::Class::DeploymentHandler::Cookbook::CustomResultSource;
3 # ABSTRACT: Customize how your DBICDH versions are stored
9 One of the reasons for the absurd level of flexibility that
10 L<DBIx::Class::DeploymentHandler> is so that you can do things that we did not
11 originally anticipate. Surprisingly, I never added a method to change the
12 table for the version storage. That's fine though, the following recipe
13 shows how one can do it in style:
15 =head2 Version Storage
17 package MyApp::Schema::DBICDHStorage;
19 # the following is necessary for some setups
20 use MyApp::Schema::DBICDHStorageResult;
23 extends 'DBIx::Class::DeploymentHandler::VersionStorage::Standard';
25 sub _build_version_rs {
26 $_[0]->schema->register_class(
28 'MyApp::Schema::DBICDHStorageResult'
30 $_[0]->schema->resultset('__VERSION')
34 __PACKAGE__->meta->make_immutable;
37 There's not a whole lot special there. The only real bit of code to point out
38 is the C<register_class> call. We make sure to point C<__VERSION> to the
39 result class that we will define next.
41 =head2 Version Result Class
43 package MyApp::Schema::DBICDHStorageResult;
44 use parent 'DBIx::Class::DeploymentHandler::VersionStorage::Standard::VersionResult';
45 __PACKAGE__->table('fl_bench_journal_versions');
48 As you can see, this is almost silly how simple it is, we just change the
49 table being set on the original result.
51 =head2 Our very own DeploymentHandler
53 package MyApp::Schema::DeploymentHandler;
55 extends 'DBIx::Class::DeploymentHandler::Dad';
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'],
64 attributes_to_copy => [qw( databases script_directory sql_translator_args )],
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 )],
72 'DBIx::Class::DeploymentHandler::WithApplicatorDumple' => {
73 interface_role => 'DBIx::Class::DeploymentHandler::HandlesVersionStorage',
74 class_name => 'MyApp::Schema::DBICDHStorage',
75 delegate_name => 'version_storage',
76 attributes_to_assume => ['schema'],
78 with 'DBIx::Class::DeploymentHandler::WithReasonableDefaults';
80 sub prepare_version_storage_install {
83 $self->prepare_resultsource_install({
84 result_source => $self->version_storage->version_rs->result_source
88 sub install_version_storage {
91 my $version = (shift || {})->{version} || $self->schema_version;
92 $self->install_resultsource({
93 result_source => $self->version_storage->version_rs->result_source,
99 $_[0]->prepare_deploy;
100 $_[0]->prepare_version_storage_install;
104 __PACKAGE__->meta->make_immutable;
107 Note: if you are using decimal numbers for versioning, you should ammend
108 this DeploymentHandler package, setting it's VersionHandler class_name from
109 Monotonic ( which handles integer only version numbers ) to ExplicitVersions
110 or DatabaseToSchemaVersions, as these handle version numbers as strings