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