1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
package DBIx::Class::DeploymentHandler::Cookbook::CustomResultSource;
$DBIx::Class::DeploymentHandler::Cookbook::CustomResultSource::VERSION = '0.002212';
# ABSTRACT: Customize how your DBICDH versions are stored
__END__
=pod
=head1 NAME
DBIx::Class::DeploymentHandler::Cookbook::CustomResultSource - Customize how your DBICDH versions are stored
=head1 DESCRIPTION
One of the reasons for the absurd level of flexibility that
L<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:
=head2 Version Storage
package MyApp::Schema::DBICDHStorage;
# the following is necessary for some setups
use MyApp::Schema::DBICDHStorageResult;
use Moose;
extends 'DBIx::Class::DeploymentHandler::VersionStorage::Standard';
sub _build_version_rs {
$_[0]->schema->register_class(
__VERSION =>
'MyApp::Schema::DBICDHStorageResult'
);
$_[0]->schema->resultset('__VERSION')
}
no Moose;
__PACKAGE__->meta->make_immutable;
1;
There's not a whole lot special there. The only real bit of code to point out
is the C<register_class> call. We make sure to point C<__VERSION> to the
result class that we will define next.
=head2 Version Result Class
package MyApp::Schema::DBICDHStorageResult;
use parent 'DBIx::Class::DeploymentHandler::VersionStorage::Standard::VersionResult';
__PACKAGE__->table('fl_bench_journal_versions');
1;
As you can see, this is almost silly how simple it is, we just change the
table being set on the original result.
=head2 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: http://rt.cpan.org/Public/Bug/Display.html?id=46347
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;
$self->prepare_resultsource_install({
result_source => $self->version_storage->version_rs->result_source
});
}
sub install_version_storage {
my $self = shift;
my $version = (shift || {})->{version} || $self->schema_version;
$self->install_resultsource({
result_source => $self->version_storage->version_rs->result_source,
version => $version,
});
}
sub prepare_install {
$_[0]->prepare_deploy;
$_[0]->prepare_version_storage_install;
}
no Moose;
__PACKAGE__->meta->make_immutable;
1;
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.
=head1 AUTHOR
Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2014 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.
=cut
|