Arthur Axel "fREW" Schmidt > DBIx-Class-DeploymentHandler-0.002202 > DBIx::Class::DeploymentHandler::Cookbook::CustomResultSource


Annotate this POD

View/Report Bugs
Source   Latest Release: DBIx-Class-DeploymentHandler-0.002210




One of the reasons for the absurd level of flexibility that DBIx::Class::DeploymentHandler is so that you can do things that we did not originally anticipate. Surprisingly, I never added a method to change the table for the version storage. That's fine though, the following recipe shows how one can do it in style:

Version Storage

 package MyApp::Schema::DBICDHStorage;
 use Moose;
 extends 'DBIx::Class::DeploymentHandler::VersionStorage::Standard';

 sub _build_version_rs {
     __VERSION =>

 no Moose;

There's not a whole lot special there. The only real bit of code to point out is the register_class call. We make sure to point __VERSION to the result class that we will define next.

Version Result Class

 package MyApp::Schema::DBICDHStorageResult;
 use parent 'DBIx::Class::DeploymentHandler::VersionStorage::Standard::VersionResult';

As you can see, this is almost silly how simple it is, we just change the table being set on the original result.

Our very own DeploymentHandler

 package MyApp::Schema::DeploymentHandler;
 use Moose;
 extends 'DBIx::Class::DeploymentHandler::Dad';

 # a single with would be better, but we can't do that
 # see:
 with 'DBIx::Class::DeploymentHandler::WithApplicatorDumple' => {
     interface_role       => 'DBIx::Class::DeploymentHandler::HandlesDeploy',
     class_name           => 'DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator',
     delegate_name        => 'deploy_method',
     attributes_to_assume => ['schema'],
     attributes_to_copy   => [qw( databases script_directory sql_translator_args )],
   'DBIx::Class::DeploymentHandler::WithApplicatorDumple' => {
     interface_role       => 'DBIx::Class::DeploymentHandler::HandlesVersioning',
     class_name           => 'DBIx::Class::DeploymentHandler::VersionHandler::Monotonic',
     delegate_name        => 'version_handler',
     attributes_to_assume => [qw( database_version schema_version to_version )],
   'DBIx::Class::DeploymentHandler::WithApplicatorDumple' => {
     interface_role       => 'DBIx::Class::DeploymentHandler::HandlesVersionStorage',
     class_name           => 'MyApp::Schema::DBICDHStorage',
     delegate_name        => 'version_storage',
     attributes_to_assume => ['schema'],
 with 'DBIx::Class::DeploymentHandler::WithReasonableDefaults';

 sub prepare_version_storage_install {
   my $self = shift;

       result_source => $self->version_storage->version_rs->result_source

 sub install_version_storage {
   my $self = shift;

   my $version = (shift || {})->{version} || $self->schema_version;
       result_source => $self->version_storage->version_rs->result_source,
       version       => $version,

 sub prepare_install {

 no Moose;

Note: if you are using decimal numbers for versioning, you should ammend this DeploymentHandler package, setting it's VersionHandler class_name from Monotonic ( which handles integer only version numbers ) to ExplicitVersions or DatabaseToSchemaVersions, as these handle version numbers as strings instead of integers.


DBIx::Class::DeploymentHandler::Cookbook::CustomResultSource - Customize how your DBICDH versions are stored


Arthur Axel "fREW" Schmidt <>


This software is copyright (c) 2012 by Arthur Axel "fREW" Schmidt.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: