diff --git a/Changes b/Changes index 5b7ce6ca..7669e1d3 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,6 @@ Changes for SQL::Translator + * sqlt-diff: Change producer_args to sqlt_args for better self-documentation * Support INCLUDE on indices for Pg (producer + parser) 1.62 - 2020-09-14 diff --git a/lib/SQL/Translator/Diff.pm b/lib/SQL/Translator/Diff.pm index fd34247d..50045a22 100644 --- a/lib/SQL/Translator/Diff.pm +++ b/lib/SQL/Translator/Diff.pm @@ -41,7 +41,7 @@ has no_batch_alters => ( has ignore_missing_methods => ( is => 'rw', ); -has producer_args => ( +has sqlt_args => ( is => 'rw', lazy => 1, default => quote_sub '{}', @@ -103,12 +103,14 @@ sub schema_diff { sub BUILD { my ($self, $args) = @_; - if ($args->{producer_options}) { - carp 'producer_options is deprecated. Please use producer_args'; - $self->producer_args({ - %{$args->{producer_options}}, - %{$self->producer_args} - }); + for my $deprecated (qw/producer_options producer_args/) { + if ($args->{$deprecated}) { + carp "$deprecated is deprecated. Please use sqlt_args"; + $self->sqlt_args({ + %{$args->{$deprecated}}, + %{$self->sqlt_args} + }); + } } if (! $self->output_db) { @@ -229,7 +231,7 @@ sub produce_diff_sql { $func_map{$_} => $self->table_diff_hash->{$table}{$_} } keys %func_map }, - $self->producer_args + $self->sqlt_args ); } } else { @@ -248,7 +250,7 @@ sub produce_diff_sql { my $meth = $producer_class->can($_); $meth ? map { - map { $_ ? "$_" : () } $meth->( (ref $_ eq 'ARRAY' ? @$_ : $_), $self->producer_args ); + map { $_ ? "$_" : () } $meth->( (ref $_ eq 'ARRAY' ? @$_ : $_), $self->sqlt_args ); } @{ $flattened_diffs{$_} } : $self->ignore_missing_methods ? "-- $producer_class cant $_" @@ -272,7 +274,8 @@ sub produce_diff_sql { producer_type => $self->output_db, add_drop_table => 0, no_comments => 1, - producer_args => $self->producer_args, + # TODO: sort out options + %{ $self->sqlt_args } ); $translator->producer_args->{no_transaction} = 1; my $schema = $translator->schema; @@ -287,7 +290,7 @@ sub produce_diff_sql { if (my @tables_to_drop = @{ $self->{tables_to_drop} || []} ) { my $meth = $producer_class->can('drop_table'); - push @diffs, $meth ? ( map { $meth->($_, $self->producer_args) } @tables_to_drop) + push @diffs, $meth ? ( map { $meth->($_, $self->sqlt_args) } @tables_to_drop) : $self->ignore_missing_methods ? "-- $producer_class cant drop_table" : die "$producer_class cant drop_table"; @@ -452,11 +455,18 @@ sub diff_table_options { unless $src_table->_compare_objects( \@src_opts, \@tar_opts ); } -# support producer_options as an alias for producer_args for legacy code. +# support producer_options as an alias for sqlt_args for legacy code. sub producer_options { my $self = shift; - return $self->producer_args( @_ ); + return $self->sqlt_args( @_ ); +} + +# support producer_args as an alias for sqlt_args for legacy code. +sub producer_args { + my $self = shift; + + return $self->sqlt_args( @_ ); } 1; @@ -519,7 +529,7 @@ supports the ability to do all alters for a table as one statement. If the diff would need a method that is missing from the producer, just emit a comment showing the method is missing, rather than dieing with an error -=item B +=item B Hash of extra arguments passed to L and the below L. diff --git a/script/sqlt-diff b/script/sqlt-diff index 2c6469c0..e8ea96d5 100755 --- a/script/sqlt-diff +++ b/script/sqlt-diff @@ -192,7 +192,7 @@ my $result = SQL::Translator::Diff::schema_diff( no_batch_alters => $no_batch_alters || 0, debug => $debug || 0, trace => $trace || 0, - producer_args => { + sqlt_args => { quote_table_names => $quote || '', quote_field_names => $quote || '', }, diff --git a/t/30sqlt-new-diff-mysql.t b/t/30sqlt-new-diff-mysql.t index 79df23f2..8e2bfb1d 100644 --- a/t/30sqlt-new-diff-mysql.t +++ b/t/30sqlt-new-diff-mysql.t @@ -39,7 +39,7 @@ my @out = SQL::Translator::Diff::schema_diff( $target_schema, 'MySQL', { no_batch_alters => 1, - producer_args => { quote_identifiers => 0 } + sqlt_args => { quote_identifiers => 0 } } ); @@ -106,7 +106,7 @@ COMMIT; $out = SQL::Translator::Diff::schema_diff($source_schema, 'MySQL', $target_schema, 'MySQL', { ignore_index_names => 1, ignore_constraint_names => 1, - producer_args => { quote_identifiers => 0 }, + sqlt_args => { quote_identifiers => 0 }, }); eq_or_diff($out, <<'## END OF DIFF', "Diff as expected", { context => 1 }); @@ -178,7 +178,7 @@ eq_or_diff($out, <<'## END OF DIFF', "No differences found", { context => 1 }); my $field = $target_schema->get_table('employee')->get_field('employee_id'); $field->data_type('integer'); $field->size(0); - $out = SQL::Translator::Diff::schema_diff($schema, 'MySQL', $target_schema, 'MySQL', { producer_args => { quote_identifiers => 0 } } ); + $out = SQL::Translator::Diff::schema_diff($schema, 'MySQL', $target_schema, 'MySQL', { sqlt_args => { quote_identifiers => 0 } } ); eq_or_diff($out, <<'## END OF DIFF', "No differences found", { context => 1 }); -- Convert schema 'create.sql' to 'create2.yml':; @@ -323,7 +323,7 @@ COMMIT; # Test quoting works too. $out = SQL::Translator::Diff::schema_diff($s1, 'MySQL', $s2, 'MySQL', - { producer_args => { quote_identifiers => 1 } } + { sqlt_args => { quote_identifiers => 1 } } ); eq_or_diff($out, <<'## END OF DIFF', "Quoting can be turned on", { context => 1 }); -- Convert schema 'Schema 3' to 'Schema 4':; diff --git a/t/30sqlt-new-diff-pgsql.t b/t/30sqlt-new-diff-pgsql.t index 471dc8f4..9e298d38 100644 --- a/t/30sqlt-new-diff-pgsql.t +++ b/t/30sqlt-new-diff-pgsql.t @@ -40,7 +40,7 @@ my $out = SQL::Translator::Diff::schema_diff( $target_schema, 'PostgreSQL', { - producer_args => { + sqlt_args => { quote_identifiers => 1, } } @@ -103,7 +103,7 @@ $out = SQL::Translator::Diff::schema_diff( $source_schema, 'PostgreSQL', $target_schema, 'PostgreSQL', { ignore_index_names => 1, ignore_constraint_names => 1, - producer_args => { + sqlt_args => { quote_identifiers => 0, } });