}
else {
$self->_upgrading_from($v);
+ last;
}
$self->naming->{relationships} ||= $v;
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;
}
{
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';
}
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);
if (Digest::MD5::md5_base64($compare_to) eq $old_md5) {
- return;
+ return unless $self->_upgrading_from && $is_schema;
}
}
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;
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;
# 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];
'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.
{