Improve docs by linking from implementations to their roles
[dbsrgits/DBIx-Class-DeploymentHandler.git] / lib / DBIx / Class / DeploymentHandler / VersionStorage / Deprecated.pm
1 package DBIx::Class::DeploymentHandler::VersionStorage::Deprecated;
2 use Moose;
3 use DBIx::Class::DeploymentHandler::Logger;
4 use Log::Contextual ':log', -package_logger =>
5   DBIx::Class::DeploymentHandler::Logger->new({
6     env_prefix => 'DBICDH'
7   });
8
9
10 # ABSTRACT: (DEPRECATED) Use this if you are stuck in the past
11
12 has schema => (
13   isa      => 'DBIx::Class::Schema',
14   is       => 'ro',
15   required => 1,
16 );
17
18 has version_rs => (
19   isa        => 'DBIx::Class::ResultSet',
20   is         => 'ro',
21   builder    => '_build_version_rs',
22   handles    => [qw( database_version version_storage_is_installed )],
23 );
24
25 with 'DBIx::Class::DeploymentHandler::HandlesVersionStorage';
26
27 use DBIx::Class::DeploymentHandler::VersionStorage::Deprecated::VersionResult;
28 sub _build_version_rs {
29   $_[0]->schema->register_class(
30     dbix_class_schema_versions =>
31       'DBIx::Class::DeploymentHandler::VersionStorage::Deprecated::VersionResult'
32   );
33   $_[0]->schema->resultset('dbix_class_schema_versions')
34 }
35
36 sub add_database_version {
37   # deprecated doesn't support ddl or upgrade_ddl
38   my $version = $_[1]->{version};
39   log_debug { "Adding database version $version" };
40   $_[0]->version_rs->create({ version => $version })
41 }
42
43 sub delete_database_version {
44   my $version = $_[1]->{version};
45   log_debug { "Deleting database version $version" };
46   $_[0]->version_rs->search({ version => $version})->delete
47 }
48
49 __PACKAGE__->meta->make_immutable;
50
51 1;
52
53 # vim: ts=2 sw=2 expandtab
54
55 __END__
56
57 =head1 DEPRECATED
58
59 I begrudgingly made this module (and other related modules) to keep porting
60 from L<DBIx::Class::Schema::Versioned> relatively simple.  I will make changes
61 to ensure that it works with output from L<DBIx::Class::Schema::Versioned> etc,
62 but I will not add any new features to it.
63
64 Once I hit major version 1 usage of this module will emit a warning.
65 On version 2 it will be removed entirely.
66
67 =head1 THIS SUCKS
68
69 Here's how to convert from that crufty old Deprecated VersionStorage to a shiny
70 new Standard VersionStorage:
71
72  my $s  = My::Schema->connect(...);
73  my $dh = DeploymentHandler({
74    schema => $s,
75  });
76
77  $dh->prepare_version_storage_install;
78  $dh->install_version_storage;
79
80  my @versions = $s->{vschema}->resultset('Table')->search(undef, {
81    order_by => 'installed',
82  })->get_column('version')->all;
83
84  $dh->version_storage->add_database_vesion({ version => $_ })
85    for @versions;
86
87 =head1 SEE ALSO
88
89 This class is an implementation of
90 L<DBIx::Class::DeploymentHandler::HandlesVersionStorage>.  Pretty much all the
91 documentation is there.