Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Fix passing of producer args from SQL::Translator::Diff." #138

Merged
merged 4 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -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
37 changes: 23 additions & 14 deletions lib/SQL/Translator/Diff.pm
Original file line number Diff line number Diff line change
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 @@ -273,7 +275,7 @@ sub produce_diff_sql {
add_drop_table => 0,
no_comments => 1,
# TODO: sort out options
%{ $self->producer_args }
%{ $self->sqlt_args }
);
$translator->producer_args->{no_transaction} = 1;
my $schema = $translator->schema;
Expand All @@ -288,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 @@ -453,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 @@ -520,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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