[Bast-commits] r8229 - in branches/DBIx-Class-Schema-Loader/current: lib/DBIx/Class/Schema/Loader t

caelum at dev.catalyst.perl.org caelum at dev.catalyst.perl.org
Sun Jan 3 20:59:54 GMT 2010


Author: caelum
Date: 2010-01-03 20:59:53 +0000 (Sun, 03 Jan 2010)
New Revision: 8229

Modified:
   branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm
   branches/DBIx-Class-Schema-Loader/current/t/25backcompat_v4.t
Log:
dumped version string is updated on Schema.pm when upgrading

Modified: branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm	2010-01-03 12:35:52 UTC (rev 8228)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm	2010-01-03 20:59:53 UTC (rev 8229)
@@ -476,6 +476,7 @@
             }
             else {
                 $self->_upgrading_from($v);
+                last;
             }
 
             $self->naming->{relationships} ||= $v;
@@ -528,7 +529,7 @@
     my $re = join '|', keys %old_classes;
     $re = qr/\b($re)\b/;
 
-    $code =~ s/$re/$old_classes{$1}/eg;
+    $code =~ s/$re/$old_classes{$1} || $1/eg;
 
     return $code;
 }
@@ -870,7 +871,7 @@
 
     {
         local $self->{version_to_dump} = $self->schema_version_to_dump;
-        $self->_write_classfile($schema_class, $schema_text);
+        $self->_write_classfile($schema_class, $schema_text, 1);
     }
 
     my $result_base_class = $self->result_base_class || 'DBIx::Class::Core';
@@ -899,7 +900,7 @@
 }
 
 sub _write_classfile {
-    my ($self, $class, $text) = @_;
+    my ($self, $class, $text, $is_schema) = @_;
 
     my $filename = $self->_get_dump_filename($class);
     $self->_ensure_dump_subdirs($class);
@@ -946,7 +947,7 @@
       
 
       if (Digest::MD5::md5_base64($compare_to) eq $old_md5) {
-        return;
+        return unless $self->_upgrading_from && $is_schema;
       }
     }
 
@@ -1070,7 +1071,8 @@
         my $old_class = join(q{::}, @result_namespace,
             $self->_table2moniker($table));
 
-        $self->_upgrading_classes->{$table_class} = $old_class;
+        $self->_upgrading_classes->{$table_class} = $old_class
+            unless $table_class eq $old_class;
     }
 
     my $table_normalized = lc $table;

Modified: branches/DBIx-Class-Schema-Loader/current/t/25backcompat_v4.t
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/t/25backcompat_v4.t	2010-01-03 12:35:52 UTC (rev 8228)
+++ branches/DBIx-Class-Schema-Loader/current/t/25backcompat_v4.t	2010-01-03 20:59:53 UTC (rev 8229)
@@ -6,6 +6,7 @@
 use Class::Unload;
 use File::Temp qw/tempfile tempdir/;
 use IO::File;
+use DBIx::Class::Schema::Loader ();
 use lib qw(t/lib);
 use make_dbictest_db2;
 
@@ -178,8 +179,6 @@
 # test running against v4 schema without upgrade, twice, then upgrade
 {
     write_v4_schema_pm();
-
-    # now run the loader
     my $res = run_loader(dump_directory => $DUMP_DIR);
     my $warning = $res->{warnings}[0];
 
@@ -259,6 +258,23 @@
 'custom content from unsingularized Result loaded into static dump correctly';
 }
 
+# test upgrading a v4 schema, the check that the version string is correct
+{
+    write_v4_schema_pm();
+    run_loader(dump_directory => $DUMP_DIR);
+    my $res = run_loader(dump_directory => $DUMP_DIR, naming => 'current');
+    my $schema = $res->{schema};
+
+    my $file = $schema->_loader->_get_dump_filename($SCHEMA_CLASS);
+    my $code = do { local ($/, @ARGV) = (undef, $file); <> };
+
+    my ($dumped_ver) =
+        $code =~ /^# Created by DBIx::Class::Schema::Loader v(\S+)/m;
+
+    is $dumped_ver, $DBIx::Class::Schema::Loader::VERSION,
+        'correct version dumped after upgrade of v4 static schema';
+}
+
 # Test upgrading an already singular result with custom content that refers to
 # old class names.
 {




More information about the Bast-commits mailing list