From: Rafael Kitover Date: Sun, 3 Jan 2010 20:59:53 +0000 (+0000) Subject: dumped version string is updated on Schema.pm when upgrading X-Git-Tag: 0.04999_14~18 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=68d49e50b625444f6cc75f3602fe80f512d729f4;p=dbsrgits%2FDBIx-Class-Schema-Loader.git dumped version string is updated on Schema.pm when upgrading --- diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 03a3021..08a7e4f 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -476,6 +476,7 @@ EOF } else { $self->_upgrading_from($v); + last; } $self->naming->{relationships} ||= $v; @@ -528,7 +529,7 @@ sub _rewrite_old_classnames { 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 @@ sub _dump_to_dir { { 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 _sig_comment { } 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 @@ sub _write_classfile { if (Digest::MD5::md5_base64($compare_to) eq $old_md5) { - return; + return unless $self->_upgrading_from && $is_schema; } } @@ -1070,7 +1071,8 @@ sub _make_src_class { 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; diff --git a/t/25backcompat_v4.t b/t/25backcompat_v4.t index 384fe96..9823000 100644 --- a/t/25backcompat_v4.t +++ b/t/25backcompat_v4.t @@ -6,6 +6,7 @@ use File::Path qw/rmtree make_path/; 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 @@ EOF # 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 @@ EOF '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. {