1 package DBIx::Class::DeploymentHandler::Cookbook::CustomResultSource;
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:
11 =head2 Version Storage
13 package MyApp::Schema::DBICDHStorage;
15 extends 'DBIx::Class::DeploymentHandler::VersionStorage::Standard';
17 sub _build_version_rs {
18 $_[0]->schema->register_class(
20 'MyApp::Schema::DBICDHStorageResult'
22 $_[0]->schema->resultset('__VERSION')
26 __PACKAGE__->meta->make_immutable;
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.
33 =head2 Version Result Class
35 package MyApp::Schema::DBICDHStorageResult;
36 use parent 'DBIx::Class::DeploymentHandler::VersionStorage::Standard::VersionResult';
37 __PACKAGE__->table('fl_bench_journal_versions');
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.
43 =head2 Our very own DeploymentHandler
45 package MyApp::Schema::DeploymentHandler;
47 extends 'DBIx::Class::DeploymentHandler::Dad';
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'],
56 attributes_to_copy => [qw( databases script_directory sql_translator_args )],
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 )],
64 'DBIx::Class::DeploymentHandler::WithApplicatorDumple' => {
65 interface_role => 'DBIx::Class::DeploymentHandler::HandlesVersionStorage',
66 class_name => 'MyApp::Schema::DBICDHStorage',
67 delegate_name => 'version_storage',
68 attributes_to_assume => ['schema'],
70 with 'DBIx::Class::DeploymentHandler::WithReasonableDefaults';
72 sub prepare_version_storage_install {
75 $self->prepare_resultsource_install({
76 result_source => $self->version_storage->version_rs->result_source
80 sub install_version_storage {
83 my $version = (shift || {})->{version} || $self->schema_version;
84 $self->install_resultsource({
85 result_source => $self->version_storage->version_rs->result_source,
91 $_[0]->prepare_deploy;
92 $_[0]->prepare_version_storage_install;
96 __PACKAGE__->meta->make_immutable;
99 Note: if you are using decimal numbers for versioning, you should ammend
100 this DeploymentHandler package, setting it's VersionHandler class_name from
101 Monotonic ( which handles integer only version numbers ) to ExplicitVersions
102 or DatabaseToSchemaVersions, as these handle version numbers as strings