Subject: | SQL::Translator::Diff::schema_diff should produce a list in list context |
Hi,
I would like to get the output of SQL::Translator::Diff::schema_diff
separated in several statements so I can feed them directly to DBI.
For that the produce_diff_sql() just needs to return a list instead of
a string in list_context.
I applied a patch to the current svn, testsuite runs. I added two tests
also.
Subject: | patch.txt |
Index: t/30sqlt-new-diff-mysql.t
===================================================================
--- t/30sqlt-new-diff-mysql.t (Revision 1588)
+++ t/30sqlt-new-diff-mysql.t (Arbeitskopie)
@@ -13,7 +13,7 @@
use SQL::Translator::Schema::Constants;
use Storable 'dclone';
-plan tests => 8;
+plan tests => 9;
use_ok('SQL::Translator::Diff') or die "Cannot continue\n";
@@ -90,6 +90,9 @@
COMMIT;
## END OF DIFF
+my @out_list_context = SQL::Translator::Diff::schema_diff( $source_schema, 'MySQL', $target_schema, 'MySQL', { no_batch_alters => 1, producer_options => { quote_table_names => 0 } } );
+my $out_list_context = join '', @out_list_context;
+eq_or_diff($out, $out_list_context, "Diff as expected in list context");
$out = SQL::Translator::Diff::schema_diff($source_schema, 'MySQL', $target_schema, 'MySQL',
{ ignore_index_names => 1,
Index: t/30sqlt-new-diff-pgsql.t
===================================================================
--- t/30sqlt-new-diff-pgsql.t (Revision 1588)
+++ t/30sqlt-new-diff-pgsql.t (Arbeitskopie)
@@ -13,7 +13,7 @@
use SQL::Translator::Schema::Constants;
use Storable 'dclone';
-plan tests => 4;
+plan tests => 5;
use_ok('SQL::Translator::Diff') or die "Cannot continue\n";
@@ -156,3 +156,8 @@
-- No differences found;
## END OF DIFF
+my @out_list_context = SQL::Translator::Diff::schema_diff(
+ $source_schema, 'PostgreSQL', $source_schema, 'PostgreSQL'
+);
+my $out_list_context = join '', @out_list_context;
+eq_or_diff($out_list_context, $out, "No differences found");
Index: lib/SQL/Translator/Diff.pm
===================================================================
--- lib/SQL/Translator/Diff.pm (Revision 1588)
+++ lib/SQL/Translator/Diff.pm (Arbeitskopie)
@@ -258,8 +258,14 @@
if ( $self->output_db !~ /^(?:MySQL|SQLite|PostgreSQL)$/ ) {
unshift(@diffs, "-- Output database @{[$self->output_db]} is untested/unsupported!!!");
}
- return join '', map { $_ ? ( $_ =~ /;$/xms ? $_ : "$_;\n\n" ) : "\n" }
- ("-- Convert schema '$src_name' to '$tar_name':", @diffs);
+ if (wantarray) {
+ return map { $_ ? ( $_ =~ /;$/xms ? $_ : "$_;\n\n" ) : "\n" }
+ ("-- Convert schema '$src_name' to '$tar_name':", @diffs);
+ }
+ else {
+ return join '', map { $_ ? ( $_ =~ /;$/xms ? $_ : "$_;\n\n" ) : "\n" }
+ ("-- Convert schema '$src_name' to '$tar_name':", @diffs);
+ }
}
return undef;