[Dbix-class] deployment_statements in list context

Daniel Westermann-Clark dwc at pobox.com
Wed Dec 23 22:50:47 GMT 2009


Hi,

Until 0.08113, the return value of
DBIx::Class::Storage::DBI::deployment_statements depended on list or
scalar context because that's how SQLT worked.  Revision 7815
introduced some error handling, but also forced scalar context.

Would anyone object to forcing list context instead?  I don't know how
many people use deployment_statements (instead of just deploy), but
returning a giant string doesn't seem terribly useful.

Attached is a patch against 0.08/trunk, with a couple of additional
tests.  Using list context simplifies the deploy method and makes it
slightly more robust.  Consider if someone is using a different
separator than semicolon.

I think I can still commit, but wanted to get thoughts before doing
so.

Thanks,

-- 
Daniel Westermann-Clark
-------------- next part --------------
Index: t/86sqlt.t
===================================================================
--- t/86sqlt.t	(revision 8160)
+++ t/86sqlt.t	(working copy)
@@ -14,6 +14,15 @@
 
 my $schema = DBICTest->init_schema (no_deploy => 1);
 
+# Test that we get deployment statements
+{
+  my @statements = $schema->deployment_statements;
+  ok(@statements > 1, 'got at least two statements');
+
+  my $statements = join "\n", @statements;
+  like($statements, qr/CREATE TABLE artist/i, 'there is a CREATE TABLE artist statement');
+}
+
 # replace the sqlt calback with a custom version ading an index
 $schema->source('Track')->sqlt_deploy_callback(sub {
   my ($self, $sqlt_table) = @_;
Index: lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- lib/DBIx/Class/Storage/DBI.pm	(revision 8160)
+++ lib/DBIx/Class/Storage/DBI.pm	(working copy)
@@ -2373,10 +2373,10 @@
     data => $schema,
   );
 
-  my $ret = $tr->translate
+  my @ret = $tr->translate
     or $self->throw_exception( 'Unable to produce deployment statements: ' . $tr->error);
 
-  return $ret;
+  return @ret;
 }
 
 sub deploy {
@@ -2401,16 +2401,10 @@
     $self->_query_end($line);
   };
   my @statements = $self->deployment_statements($schema, $type, undef, $dir, { %{ $sqltargs || {} }, no_comments => 1 } );
-  if (@statements > 1) {
-    foreach my $statement (@statements) {
-      $deploy->( $statement );
-    }
+
+  foreach my $statement (@statements) {
+    $deploy->( $statement );
   }
-  elsif (@statements == 1) {
-    foreach my $line ( split(";\n", $statements[0])) {
-      $deploy->( $line );
-    }
-  }
 }
 
 =head2 datetime_parser
Index: Changes
===================================================================
--- Changes	(revision 8160)
+++ Changes	(working copy)
@@ -8,6 +8,8 @@
         - Views without a view_definition will throw an exception when
           parsed by SQL::Translator::Parser::DBIx::Class
         - Schema POD improvement for dclone
+        - Force deployment_statements to return a list, which simplifies
+          deploy
 
 0.08115 2009-12-10 09:02:00 (CST)
         - Real limit/offset support for MSSQL server (via Row_Number)


More information about the DBIx-Class mailing list