insert ddl into database; fix tests to ingore that
Arthur Axel 'fREW' Schmidt [Sat, 20 Mar 2010 22:14:50 +0000 (17:14 -0500)]
lib/DBIx/Class/DeploymentHandler.pm
lib/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm
t/version_storages/standard.t

index 1690096..64c8d49 100644 (file)
@@ -65,17 +65,12 @@ method install {
   carp 'Install not possible as versions table already exists in database'
     if $self->version_storage_is_installed;
 
-  my $new_version = $self->to_version;
+  my $ddl = $self->_deploy;
 
-  if ($new_version) {
-    $self->_deploy;
-
-    $self->version_storage->add_database_version({
-      version     => $new_version,
-      # ddl         => $ddl,
-      # upgrade_sql => $upgrade_sql,
-    });
-  }
+  $self->version_storage->add_database_version({
+    version     => $self->to_version,
+    ddl         => $ddl,
+  });
 }
 
 sub upgrade {
index 2cea383..5ec655e 100644 (file)
@@ -148,12 +148,12 @@ sub _deploy {
 
   my $guard = $self->schema->txn_scope_guard if $self->txn_wrap;
 
-  foreach my $line (
-    map @{$self->_read_sql_file($_)}, @{$self->_ddl_schema_consume_filenames(
+  my @sql = map @{$self->_read_sql_file($_)}, @{$self->_ddl_schema_consume_filenames(
       $self->storage->sqlt_type,
       $self->schema_version
-    )}
-  ) {
+    )};
+
+  foreach my $line (@sql) {
     $storage->_query_start($line);
     try {
       # do a dbh_do cycle here, as we need some error checking in
@@ -167,6 +167,7 @@ sub _deploy {
   }
 
   $guard->commit if $self->txn_wrap;
+  return join "\n", @sql;
 }
 
 sub prepare_install {
index aa357ce..dcd4c2f 100644 (file)
@@ -45,17 +45,11 @@ $handler->install();
 ok( $vs->version_storage_is_installed, 'VersionStorage is now installed' );
 
 
-cmp_deeply(
-       [ map +{
-               version     => $_->version,
-               ddl         => $_->ddl,
-               upgrade_sql => $_->upgrade_sql,
-       }, $vs->version_rs->search(undef, {order_by => 'id'})->all],
-       [{
-               version     => '1.0',
-               ddl         => undef,
-               upgrade_sql => undef
-       }],
+ok(
+       eq_array(
+               [ $vs->version_rs->search(undef, {order_by => 'id'})->get_column('version')->all],
+               [ '1.0' ],
+       ),
        'initial version works correctly'
 );
 
@@ -65,21 +59,11 @@ $vs->add_database_version({
 });
 is( $vs->database_version, '2.0', 'database version is 2.0');
 
-cmp_deeply(
-       [ map +{
-               version     => $_->version,
-               ddl         => $_->ddl,
-               upgrade_sql => $_->upgrade_sql,
-       }, $vs->version_rs->search(undef, {order_by => 'id'})->all],
-       [{
-               version     => '1.0',
-               ddl         => undef,
-               upgrade_sql => undef
-       },{
-               version     => '2.0',
-               ddl         => undef,
-               upgrade_sql => undef
-       }],
+ok(
+       eq_array(
+               [ $vs->version_rs->search(undef, {order_by => 'id'})->get_column('version')->all],
+               [ '1.0', '2.0', ],
+       ),
        'adding another version works correctly'
 );