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