working deprecated bundle
Arthur Axel 'fREW' Schmidt [Sat, 27 Mar 2010 08:05:36 +0000 (03:05 -0500)]
lib/DBIx/Class/DeploymentHandler/Deprecated.pm
lib/DBIx/Class/DeploymentHandler/Deprecated/WithDeprecatedVersionStorage.pm
lib/DBIx/Class/DeploymentHandler/VersionStorage/Deprecated.pm
lib/DBIx/Class/DeploymentHandler/VersionStorage/Deprecated/VersionResult.pm
lib/DBIx/Class/DeploymentHandler/VersionStorage/Deprecated/VersionResultSet.pm
lib/DBIx/Class/DeploymentHandler/WithExplicitVersions.pm [new file with mode: 0644]
lib/DBIx/Class/DeploymentHandler/WithStandardVersionStorage.pm
t/02-instantiation.t
t/03-deprecated.t
t/lib/DBICDHTest.pm

index 5024417..d13faf4 100644 (file)
@@ -10,15 +10,15 @@ with 'DBIx::Class::DeploymentHandler::Deprecated::WithDeprecatedSqltDeployMethod
 sub BUILD {
   my $self = shift;
 
-  if ($self->schema->can('ordered_versions')) {
+  if ($self->schema->can('ordered_versions') && $self->schema->ordered_versions) {
     apply_all_roles(
       $self,
-      'DBIx::Class::DeploymentHandler::WithDatabaseToSchemaVersions'
+      'DBIx::Class::DeploymentHandler::WithExplicitVersions'
     );
   } else {
     apply_all_roles(
       $self,
-      'DBIx::Class::DeploymentHandler::WithExplicitVersions'
+      'DBIx::Class::DeploymentHandler::WithDatabaseToSchemaVersions'
     );
   }
 }
index b8bf470..7ead82a 100644 (file)
@@ -6,7 +6,7 @@ use DBIx::Class::DeploymentHandler::VersionStorage::Deprecated;
 has version_storage => (
   does => 'DBIx::Class::DeploymentHandler::HandlesVersionStorage',
   is  => 'ro',
-  lazy_build => 1,
+  builder => '_build_version_storage',
   handles =>  'DBIx::Class::DeploymentHandler::HandlesVersionStorage',
 );
 
index 385d070..72ffb3c 100644 (file)
@@ -1,4 +1,4 @@
-package DBIx::Class::DeploymentHandler::VersionStorage::Standard;
+package DBIx::Class::DeploymentHandler::VersionStorage::Deprecated;
 use Moose;
 use Method::Signatures::Simple;
 
@@ -11,12 +11,13 @@ has schema => (
 has version_rs => (
   isa        => 'DBIx::Class::ResultSet',
   is         => 'ro',
-  lazy_build => 1,
+  builder    => '_build_version_rs',
   handles    => [qw( database_version version_storage_is_installed )],
 );
 
 with 'DBIx::Class::DeploymentHandler::HandlesVersionStorage';
 
+use DBIx::Class::DeploymentHandler::VersionStorage::Deprecated::VersionResult;
 sub _build_version_rs {
   $_[0]->schema->register_class(
     dbix_class_schema_versions =>
index 072d8f7..14d6268 100644 (file)
@@ -5,7 +5,7 @@ use warnings;
 
 use parent 'DBIx::Class::Core';
 
-__PACKAGE__->table('dbix_class_deploymenthandler_versions');
+__PACKAGE__->table('dbix_class_schema_versions');
 
 __PACKAGE__->add_columns (
    version => {
index cc4699b..cff502c 100644 (file)
@@ -24,12 +24,13 @@ sub database_version {
 # this is why it's deprecated guys... Serially.
 sub create {
   my $self = shift;
+  my $args = shift;
 
   my @tm = gettimeofday();
   my @dt = gmtime ($tm[0]);
 
   $self->next::method({
-    version => $version,
+    %{$args},
     installed => sprintf("v%04d%02d%02d_%02d%02d%02d.%03.0f",
       $dt[5] + 1900,
       $dt[4] + 1,
diff --git a/lib/DBIx/Class/DeploymentHandler/WithExplicitVersions.pm b/lib/DBIx/Class/DeploymentHandler/WithExplicitVersions.pm
new file mode 100644 (file)
index 0000000..bc89112
--- /dev/null
@@ -0,0 +1,31 @@
+package DBIx::Class::DeploymentHandler::WithExplicitVersions;
+use Moose::Role;
+
+use DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions;
+
+use Carp 'carp';
+
+has version_handler => (
+  is         => 'ro',
+  lazy_build => 1,
+  does       => 'DBIx::Class::DeploymentHandler::HandlesVersioning',
+  handles    => 'DBIx::Class::DeploymentHandler::HandlesVersioning',
+);
+
+sub _build_version_handler {
+  my $self = shift;
+
+  my $args = {
+    database_version => $self->database_version,
+    schema_version   => $self->schema_version,
+  };
+
+  $args->{to_version} = $self->to_version if $self->has_to_version;
+  DBIx::Class::DeploymentHandler::VersionHandler::ExplicitVersions->new($args);
+}
+
+1;
+
+__END__
+
+vim: ts=2 sw=2 expandtab
index afcc1d5..7abe9cf 100644 (file)
@@ -6,7 +6,7 @@ use DBIx::Class::DeploymentHandler::VersionStorage::Standard;
 has version_storage => (
   does => 'DBIx::Class::DeploymentHandler::HandlesVersionStorage',
   is  => 'ro',
-  lazy_build => 1,
+  builder => '_build_version_storage',
   handles =>  'DBIx::Class::DeploymentHandler::HandlesVersionStorage',
 );
 
index 4f8ca04..29fb08d 100644 (file)
 #!perl
 
-use Test::More;
-use Test::Exception;
-use File::Path 'remove_tree';
-
 use lib 't/lib';
 use DBICDHTest;
 use DBIx::Class::DeploymentHandler;
-my $db = 'dbi:SQLite:db.db';
-my @connection = ($db, '', '', { ignore_version => 1 });
-my $sql_dir = 't/sql';
-
-DBICDHTest::ready;
-
-VERSION1: {
-   use_ok 'DBICVersion_v1';
-   my $s = DBICVersion::Schema->connect(@connection);
-   ok($s, 'DBICVersion::Schema 1.0 instantiates correctly');
-   my $handler = DBIx::Class::DeploymentHandler->new({
-      upgrade_directory => $sql_dir,
-      schema => $s,
-      databases => 'SQLite',
-      sqltargs => { add_drop_table => 0 },
-   });
-
-   ok($handler, 'DBIx::Class::DeploymentHandler w/1.0 instantiates correctly');
-
-   my $version = $s->schema_version();
-   $handler->prepare_install();
-
-   dies_ok {
-      $s->resultset('Foo')->create({
-         bar => 'frew',
-      })
-   } 'schema not deployed';
-   $handler->install;
-   dies_ok {
-     $handler->install;
-   } 'cannot install twice';
-   lives_ok {
-      $s->resultset('Foo')->create({
-         bar => 'frew',
-      })
-   } 'schema is deployed';
-}
-
-VERSION2: {
-   use_ok 'DBICVersion_v2';
-   my $s = DBICVersion::Schema->connect(@connection);
-   ok($s, 'DBICVersion::Schema 2.0 instantiates correctly');
-   my $handler = DBIx::Class::DeploymentHandler->new({
-      upgrade_directory => $sql_dir,
-      schema => $s,
-      databases => 'SQLite',
-   });
-
-   ok($handler, 'DBIx::Class::DeploymentHandler w/2.0 instantiates correctly');
-
-   $version = $s->schema_version();
-   $handler->prepare_install();
-   $handler->prepare_upgrade('1.0', $version);
-   $handler->prepare_upgrade($version, '1.0');
-   dies_ok {
-      $s->resultset('Foo')->create({
-         bar => 'frew',
-         baz => 'frew',
-      })
-   } 'schema not deployed';
-   dies_ok {
-      $s->resultset('Foo')->create({
-         bar => 'frew',
-         baz => 'frew',
-      })
-   } 'schema not uppgrayyed';
-   $handler->upgrade;
-   lives_ok {
-      $s->resultset('Foo')->create({
-         bar => 'frew',
-         baz => 'frew',
-      })
-   } 'schema is deployed';
-}
-
-VERSION3: {
-   use_ok 'DBICVersion_v3';
-   my $s = DBICVersion::Schema->connect(@connection);
-   ok($s, 'DBICVersion::Schema 3.0 instantiates correctly');
-   my $handler = DBIx::Class::DeploymentHandler->new({
-      upgrade_directory => $sql_dir,
-      schema => $s,
-      databases => 'SQLite',
-   });
-
-   ok($handler, 'DBIx::Class::DeploymentHandler w/3.0 instantiates correctly');
+use Test::More;
 
-   $version = $s->schema_version();
-   $handler->prepare_install;
-   $handler->prepare_upgrade( '1.0', $version );
-   $handler->prepare_upgrade( '2.0', $version );
-   dies_ok {
-      $s->resultset('Foo')->create({
-            bar => 'frew',
-            baz => 'frew',
-            biff => 'frew',
-         })
-   } 'schema not deployed';
-   $handler->upgrade;
-   lives_ok {
-      $s->resultset('Foo')->create({
-         bar => 'frew',
-         baz => 'frew',
-         biff => 'frew',
-      })
-   } 'schema is deployed';
-}
+DBICDHTest::test_bundle(DBIx::Class::DeploymentHandler);
 
 done_testing;
-__END__
-
-vim: ts=2 sw=2 expandtab
index 10fbc2d..f69f2e9 100644 (file)
@@ -1,10 +1,10 @@
 #!perl
 
+use lib 't/lib';
+use DBICDHTest;
+use DBIx::Class::DeploymentHandler::Deprecated;
 use Test::More;
 
-use_ok 'DBIx::Class::DeploymentHandler::Deprecated';
+DBICDHTest::test_bundle(DBIx::Class::DeploymentHandler::Deprecated);
 
 done_testing;
-__END__
-
-vim: ts=2 sw=2 expandtab
index 6b76475..08a7db2 100644 (file)
@@ -4,6 +4,8 @@ use strict;
 use warnings;
 
 use File::Path 'remove_tree';
+use Test::More;
+use Test::Exception;
 
 sub ready {
    unlink 'db.db' if -e 'db.db';
@@ -13,5 +15,116 @@ sub ready {
    }
 }
 
+sub test_bundle {
+       my $bundle = shift;
+       my $db = 'dbi:SQLite:db.db';
+       my @connection = ($db, '', '', { ignore_version => 1 });
+       my $sql_dir = 't/sql';
+
+       ready;
+
+       VERSION1: {
+               use_ok 'DBICVersion_v1';
+               my $s = DBICVersion::Schema->connect(@connection);
+               ok($s, 'DBICVersion::Schema 1.0 instantiates correctly');
+               my $handler = $bundle->new({
+                       upgrade_directory => $sql_dir,
+                       schema => $s,
+                       databases => 'SQLite',
+                       sqltargs => { add_drop_table => 0 },
+               });
+
+               ok($handler, 'DBIx::Class::DeploymentHandler w/1.0 instantiates correctly');
+
+               my $version = $s->schema_version();
+               $handler->prepare_install();
+
+               dies_ok {
+                       $s->resultset('Foo')->create({
+                               bar => 'frew',
+                       })
+               } 'schema not deployed';
+               $handler->install;
+               dies_ok {
+                 $handler->install;
+               } 'cannot install twice';
+               lives_ok {
+                       $s->resultset('Foo')->create({
+                               bar => 'frew',
+                       })
+               } 'schema is deployed';
+       }
+
+       VERSION2: {
+               use_ok 'DBICVersion_v2';
+               my $s = DBICVersion::Schema->connect(@connection);
+               ok($s, 'DBICVersion::Schema 2.0 instantiates correctly');
+               my $handler = $bundle->new({
+                       upgrade_directory => $sql_dir,
+                       schema => $s,
+                       databases => 'SQLite',
+               });
+
+               ok($handler, 'DBIx::Class::DeploymentHandler w/2.0 instantiates correctly');
+
+               my $version = $s->schema_version();
+               $handler->prepare_install();
+               $handler->prepare_upgrade('1.0', $version);
+               $handler->prepare_upgrade($version, '1.0');
+               dies_ok {
+                       $s->resultset('Foo')->create({
+                               bar => 'frew',
+                               baz => 'frew',
+                       })
+               } 'schema not deployed';
+               dies_ok {
+                       $s->resultset('Foo')->create({
+                               bar => 'frew',
+                               baz => 'frew',
+                       })
+               } 'schema not uppgrayyed';
+               $handler->upgrade;
+               lives_ok {
+                       $s->resultset('Foo')->create({
+                               bar => 'frew',
+                               baz => 'frew',
+                       })
+               } 'schema is deployed';
+       }
+
+       VERSION3: {
+               use_ok 'DBICVersion_v3';
+               my $s = DBICVersion::Schema->connect(@connection);
+               ok($s, 'DBICVersion::Schema 3.0 instantiates correctly');
+               my $handler = $bundle->new({
+                       upgrade_directory => $sql_dir,
+                       schema => $s,
+                       databases => 'SQLite',
+               });
+
+               ok($handler, 'DBIx::Class::DeploymentHandler w/3.0 instantiates correctly');
+
+               my $version = $s->schema_version();
+               $handler->prepare_install;
+               $handler->prepare_upgrade( '1.0', $version );
+               $handler->prepare_upgrade( '2.0', $version );
+               dies_ok {
+                       $s->resultset('Foo')->create({
+                                       bar => 'frew',
+                                       baz => 'frew',
+                                       biff => 'frew',
+                               })
+               } 'schema not deployed';
+               $handler->upgrade;
+               lives_ok {
+                       $s->resultset('Foo')->create({
+                               bar => 'frew',
+                               baz => 'frew',
+                               biff => 'frew',
+                       })
+               } 'schema is deployed';
+       }
+}
+
 
 1;