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