when running perl scripts in deploy, use a $schema that is generated from the current...
John Napiorkowski [Tue, 27 Dec 2011 17:39:02 +0000 (12:39 -0500)]
dist.ini
lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm
lib/DBIx/Class/DeploymentHandler/HandlesProvideSchema.pm [new file with mode: 0644]
lib/DBIx/Class/DeploymentHandler/ProvideSchema/FromCurrent.pm [new file with mode: 0644]
lib/DBIx/Class/DeploymentHandler/ProvideSchema/SchemaLoader.pm [new file with mode: 0644]

index ce42169..83bf0e9 100644 (file)
--- a/dist.ini
+++ b/dist.ini
@@ -38,3 +38,4 @@ DBD::SQLite                 = 0
 Carp                        = 0
 Carp::Clan                  = 0
 aliased                     = 0
+DBIx::Class::Schema::Loader = 0.07017
index 5fb6918..8e5c50e 100644 (file)
@@ -24,6 +24,14 @@ use File::Spec::Functions;
 
 with 'DBIx::Class::DeploymentHandler::HandlesDeploy';
 
+with 'DBIx::Class::DeploymentHandler::WithApplicatorDumple' => {
+    interface_role       => 'DBIx::Class::DeploymentHandler::HandlesProvideSchema',
+    class_name           => 'DBIx::Class::DeploymentHandler::ProvideSchema::SchemaLoader',
+    delegate_name        => 'schema_provider',
+    attributes_to_assume => ['schema'],
+    attributes_to_copy   => [qw( schema )],
+  };
+
 has ignore_ddl => (
   isa      => 'Bool',
   is       => 'ro',
@@ -303,7 +311,7 @@ sub _run_perl {
   if ($@) {
     croak "$filename failed to compile: $@";
   } elsif (ref $fn eq 'CODE') {
-    $fn->($self->schema, $versions)
+    $fn->($self->migration_schema, $versions)
   } else {
     croak "$filename should define an anonymouse sub that takes a schema but it didn't!";
   }
diff --git a/lib/DBIx/Class/DeploymentHandler/HandlesProvideSchema.pm b/lib/DBIx/Class/DeploymentHandler/HandlesProvideSchema.pm
new file mode 100644 (file)
index 0000000..6a0fd25
--- /dev/null
@@ -0,0 +1,34 @@
+package DBIx::Class::DeploymentHandler::HandlesProvideSchema;
+use Moose::Role;
+
+# ABSTRACT: Interface for providing a $schema to the deployment scripts
+
+requires 'migration_schema';
+
+1;
+
+# vim: ts=2 sw=2 expandtab
+
+__END__
+
+=method schema_for_run_files
+
+  my $schema = $dh->schema_for_run_files;
+
+Provides a L<DBIx::Class::Schema> object that we can pass to the Perl deploy
+scripts.
+
+=head1 KNOWN IMPLEMENTATIONS
+
+=over
+
+=item *
+
+L<DBIx::Class::DeploymentHandler::ProvideSchema::FromCurrent>
+
+=item *
+
+L<DBIx::Class::DeploymentHandler::ProvideSchema::SQL::SchemaLoader>
+
+=back
+
diff --git a/lib/DBIx/Class/DeploymentHandler/ProvideSchema/FromCurrent.pm b/lib/DBIx/Class/DeploymentHandler/ProvideSchema/FromCurrent.pm
new file mode 100644 (file)
index 0000000..7129a25
--- /dev/null
@@ -0,0 +1,22 @@
+package DBIx::Class::DeploymentHandler::ProvideSchema::SQL::FromCurrent;
+
+use Moose;
+with 'DBIx::Class::DeploymentHandler::HandlesProvideSchema';
+
+has schema => (is=>'ro', required=>1);
+
+sub migration_schema { shift->schema }
+
+1;
+
+# vim: ts=2 sw=2 expandtab
+
+__END__
+
+=method schema_for_run_files
+
+  my $schema = $dh->schema_for_run_files;
+
+Provides a L<DBIx::Class::Schema> object that we can pass to the Perl deploy
+scripts.  We just return whatever C<$schema> you passed when you instantiated
+the L<DBIx::Class::DeploymentHandler> object.
diff --git a/lib/DBIx/Class/DeploymentHandler/ProvideSchema/SchemaLoader.pm b/lib/DBIx/Class/DeploymentHandler/ProvideSchema/SchemaLoader.pm
new file mode 100644 (file)
index 0000000..b8ac00f
--- /dev/null
@@ -0,0 +1,36 @@
+package DBIx::Class::DeploymentHandler::ProvideSchema::SchemaLoader;
+
+use Moose;
+use DBIx::Class::Schema::Loader;
+
+with 'DBIx::Class::DeploymentHandler::HandlesProvideSchema';
+
+has schema => (is=>'ro', required=>1);
+
+my %opts = (
+  naming => { ALL => 'v7'},
+  use_namespaces => 1,
+  debug => $ENV{DBIC_DEPLOYMENTHANDLER_DEBUG}||0);
+
+my $cnt = 0;
+
+sub migration_schema {
+  my $schema = shift->schema->clone;
+  my $name = ref($schema) . $cnt++;
+  DBIx::Class::Schema::Loader::make_schema_at
+    $name, \%opts, [ sub {$schema->storage->dbh} ];
+}
+
+1;
+
+# vim: ts=2 sw=2 expandtab
+
+__END__
+
+=method schema_for_run_files
+
+  my $schema = $dh->schema_for_run_files;
+
+Provides a L<DBIx::Class::Schema> object that we can pass to the Perl deploy
+scripts.  We reverse engineer a C<$schema> from whatever is currently deployed
+to the database using L<DBIx::Class::Schema::Loader>