--ignore-proc-sql Ignore procedure SQL differences
--no-batch-alters Do not clump multile alters to the same table into a
single ALTER TABLE statement where possible.
+ --quote=<character> Use <character> to quote all table and field
+ names in statements
=head1 DESCRIPTION
my ( @input, $list, $help, $debug, $trace, $caseopt, $ignore_index_names,
$ignore_constraint_names, $output_db, $mysql_parser_version,
- $ignore_view_sql, $ignore_proc_sql, $no_batch_alters );
+ $ignore_view_sql, $ignore_proc_sql, $no_batch_alters, $quote
+);
for my $arg ( @ARGV ) {
if ( $arg =~ m/^-?-l(ist)?$/ ) {
$list = 1;
elsif ( $arg =~ m/^--ignore-proc-sql$/ ) {
$ignore_proc_sql = 1;
}
+ elsif ( $arg =~ m/^--quote=(.)$/ ) {
+ $quote = $1;
+ }
elsif ( $arg =~ m/^([^=]+)=(.+)$/ ) {
push @input, { file => $1, parser => $2 };
}
elsif ( $arg =~ m/^--no-batch-alters$/ ) {
- $no_batch_alters = 1;
+ $no_batch_alters = 1;
}
else {
pod2usage( msg => "Unknown argument '$arg'" );
}
}
-print STDERR <<'EOM';
+print STDERR <<'EOM' unless $ENV{SQLT_NEWDIFF_NOWARN};
This code is experimental, currently the new code only supports MySQL or
SQLite diffing. To add support for other databases, please patch the relevant
SQL::Translator::Producer:: module. If you need compatibility with the old
output_db => $output_db,
no_batch_alters => $no_batch_alters,
debug => $debug,
- trace => $trace });
+ trace => $trace,
+ producer_args => {
+ quote_table_names => $quote,
+ quote_field_names => $quote,
+ },
+ });
if($result)
{
print $result;
--- /dev/null
+#!/usr/bin/perl
+# vim: set ft=perl:
+
+use strict;
+
+use File::Spec::Functions qw(catfile updir tmpdir);
+use FindBin qw($Bin);
+use Test::More;
+use Test::SQL::Translator qw(maybe_plan);
+
+my @script = qw(script sqlt-diff);
+my @create1 = qw(data sqlite create.sql);
+my @create2 = qw(data sqlite create2.sql);
+
+my $sqlt_diff = catfile($Bin, updir, @script);
+my $create1 = catfile($Bin, @create1);
+my $create2 = catfile($Bin, @create2);
+
+BEGIN {
+ maybe_plan(16,
+ 'SQL::Translator::Parser::MySQL',
+ );
+}
+
+$ENV{SQLT_NEWDIFF_NOWARN} = 1;
+
+my @mysql_create1 = qw(data mysql create.sql);
+my @mysql_create2 = qw(data mysql create2.sql);
+
+my $mysql_create1 = (-d "t")
+ ? catfile($Bin, @mysql_create1)
+ : catfile($Bin, "t", @mysql_create1);
+
+my $mysql_create2 = (-d "t")
+ ? catfile($Bin, @mysql_create2)
+ : catfile($Bin, "t", @mysql_create2);
+
+# Test for differences
+my @cmd = ($^X, $sqlt_diff, "$mysql_create1=MySQL", "$mysql_create2=MySQL");
+my $out = `@cmd`;
+
+like($out, qr/CHANGE COLUMN person_id/, "Detected altered 'person_id' field");
+like($out, qr/CHANGE COLUMN iq/, "Detected altered 'iq' field");
+like($out, qr/CHANGE COLUMN name/, "Detected altered 'name' field");
+like($out, qr/CHANGE COLUMN age/, "Detected altered 'age' field");
+like($out, qr/ADD COLUMN is_rock_star/,
+ "Detected missing rock star field");
+like($out, qr/ADD UNIQUE UC_person_id/,
+ "Detected missing unique constraint");
+like($out, qr/ADD UNIQUE INDEX unique_name/,
+ "Detected unique index with different name");
+like($out, qr/DROP FOREIGN KEY FK5302D47D93FE702E/,
+ "Detected drop foreign key");
+like($out, qr/ADD CONSTRAINT FK5302D47D93FE702E_diff/,
+ "Detected add constraint");
+unlike($out, qr/ADD PRIMARY KEY/, "Primary key looks different when it shouldn't");
+
+# Test for quoted output
+@cmd = ($^X, $sqlt_diff, '--quote=\`', "$mysql_create1=MySQL", "$mysql_create2=MySQL");
+$out = `@cmd`;
+
+like($out, qr/ALTER TABLE `person`/, "Quoted table name");
+like($out, qr/CHANGE COLUMN `person_id`/, "Quoted 'person_id' field");
+like($out, qr/CHANGE COLUMN `iq`/, "Quoted 'iq' field");
+like($out, qr/CHANGE COLUMN `name`/, "Quoted 'name' field");
+like($out, qr/CHANGE COLUMN `age`/, "Quoted 'age' field");
+
+# Test for sameness
+@cmd = ($^X, $sqlt_diff, "$mysql_create1=MySQL", "$mysql_create1=MySQL");
+$out = `@cmd`;
+
+like($out, qr/No differences found/, "Properly detected no differences");