Skip to content

Commit

Permalink
Revert "Fix passing of producer args from SQL::Translator::Diff." (#138)
Browse files Browse the repository at this point in the history
* Revert "Fix passing of producer args from SQL::Translator::Diff. (#117)"

This reverts commit ccbb34c.

* change producer_args for SQLT-Diff to sqlt_args

  * add deprecation shim

* add Changes

* update sqlt-diff also
  • Loading branch information
rabbiveesh committed Jul 8, 2022
1 parent 8faa4e8 commit 2fb673e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 21 deletions.
1 change: 1 addition & 0 deletions 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
Expand Down
38 changes: 24 additions & 14 deletions lib/SQL/Translator/Diff.pm
Expand Up @@ -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 '{}',
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 $_"
Expand All @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<producer_args>
=item B<sqlt_args>
Hash of extra arguments passed to L<SQL::Translator/new> and the below
L</PRODUCER FUNCTIONS>.
Expand Down
2 changes: 1 addition & 1 deletion script/sqlt-diff
Expand Up @@ -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 || '',
},
Expand Down
8 changes: 4 additions & 4 deletions t/30sqlt-new-diff-mysql.t
Expand Up @@ -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 }
}
);

Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -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':;
Expand Down Expand Up @@ -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':;
Expand Down
4 changes: 2 additions & 2 deletions t/30sqlt-new-diff-pgsql.t
Expand Up @@ -40,7 +40,7 @@ my $out = SQL::Translator::Diff::schema_diff(
$target_schema,
'PostgreSQL',
{
producer_args => {
sqlt_args => {
quote_identifiers => 1,
}
}
Expand Down Expand Up @@ -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,
}
});
Expand Down

0 comments on commit 2fb673e

Please sign in to comment.