super basic version handlers
Arthur Axel 'fREW' Schmidt [Thu, 25 Feb 2010 05:34:41 +0000 (23:34 -0600)]
lib/DBIx/Class/DeploymentHandler.pm
lib/DBIx/Class/DeploymentHandler/DatabaseToSchemaVersions.pm [new file with mode: 0644]
lib/DBIx/Class/DeploymentHandler/ExplicitVersions.pm [new file with mode: 0644]
lib/DBIx/Class/DeploymentHandler/WithDatabaseToSchemaVersions.pm [new file with mode: 0644]

index c06f124..e595e46 100644 (file)
@@ -7,6 +7,7 @@ require DBIx::Class::ResultSet; # loaded for type constraint
 use Carp::Clan '^DBIx::Class::DeploymentHandler';
 
 with 'DBIx::Class::DeploymentHandler::WithSqltDeployMethod';
+with 'DBIx::Class::DeploymentHandler::WithDatabaseToSchemaVersions';
 
 BEGIN {
   use Moose::Util::TypeConstraints;
@@ -87,8 +88,6 @@ method install($new_version) {
   }
 }
 
-method ordered_schema_versions { undef }
-
 method upgrade {
   my $db_version     = $self->db_version;
   my $schema_version = $self->schema_version;
@@ -105,8 +104,7 @@ method upgrade {
     return;
   }
 
-  my @version_list = $self->ordered_schema_versions ||
-    ( $db_version, $schema_version );
+  my @version_list = $self->ordered_schema_versions;
 
   # remove all versions in list above the required version
   while ( @version_list && ( $version_list[-1] ne $schema_version ) ) {
diff --git a/lib/DBIx/Class/DeploymentHandler/DatabaseToSchemaVersions.pm b/lib/DBIx/Class/DeploymentHandler/DatabaseToSchemaVersions.pm
new file mode 100644 (file)
index 0000000..0c4a249
--- /dev/null
@@ -0,0 +1,34 @@
+package DBIx::Class::DeploymentHandler::DatabaseToSchemaVersions;
+use Moose;
+use Method::Signatures::Simple;
+
+has schema => (
+  isa      => 'DBIx::Class::Schema',
+  is       => 'ro',
+  required => 1,
+  handles => [qw( ddl_filename schema_version )],
+);
+
+has version_rs => (
+  isa        => 'DBIx::Class::ResultSet',
+  is         => 'ro',
+  lazy_build => 1,
+  handles    => [qw( is_installed db_version )],
+);
+
+method _build_version_rs {
+   $self->schema->set_us_up_the_bomb;
+   $self->schema->resultset('__VERSION')
+}
+
+method ordered_schema_versions {
+  ( $self->db_version, $self->schema_version)
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
+
+__END__
+
+vim: ts=2 sw=2 expandtab
diff --git a/lib/DBIx/Class/DeploymentHandler/ExplicitVersions.pm b/lib/DBIx/Class/DeploymentHandler/ExplicitVersions.pm
new file mode 100644 (file)
index 0000000..da87886
--- /dev/null
@@ -0,0 +1,13 @@
+package DBIx::Class::DeploymentHandler::ExplicitVersions;
+use Moose;
+use Method::Signatures::Simple;
+
+method ordered_schema_versions { undef }
+
+__PACKAGE__->meta->make_immutable;
+
+1;
+
+__END__
+
+vim: ts=2 sw=2 expandtab
diff --git a/lib/DBIx/Class/DeploymentHandler/WithDatabaseToSchemaVersions.pm b/lib/DBIx/Class/DeploymentHandler/WithDatabaseToSchemaVersions.pm
new file mode 100644 (file)
index 0000000..9cdba4c
--- /dev/null
@@ -0,0 +1,33 @@
+package DBIx::Class::DeploymentHandler::WithDatabaseToSchemaVersions;
+use Moose::Role;
+
+use DBIx::Class::DeploymentHandler::DatabaseToSchemaVersions;
+
+use Carp 'carp';
+
+has version_handler => (
+
+# < mst> isa => 'DBIx::Class::DeploymentHandler::SqltDeployMethod',
+# < mst> should be
+# < mst> does => <some role>
+# < mst> and that role should supply those methods
+# < mst> then you can pass handles => <some role> as well
+
+  isa => 'DBIx::Class::DeploymentHandler::DatabaseToSchemaVersions',
+  is  => 'ro',
+  lazy_build => 1,
+  handles => [qw{ ordered_schema_versions }],
+);
+
+sub _build_version_handler {
+  my $self = shift;
+  DBIx::Class::DeploymentHandler::DatabaseToSchemaVersions->new({
+    schema => $self->schema,
+  });
+}
+
+1;
+
+__END__
+
+vim: ts=2 sw=2 expandtab