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