From 4e1c0d4276d81d2f696063db653224e46d262963 Mon Sep 17 00:00:00 2001 From: Diab Jerius Date: Tue, 4 Aug 2015 17:46:46 -0400 Subject: [PATCH 1/2] JSON & YAML parsers now track table comments --- lib/SQL/Translator/Parser/JSON.pm | 4 ++++ lib/SQL/Translator/Parser/YAML.pm | 3 +++ 2 files changed, 7 insertions(+) diff --git a/lib/SQL/Translator/Parser/JSON.pm b/lib/SQL/Translator/Parser/JSON.pm index 937971bc..96e1e1d9 100644 --- a/lib/SQL/Translator/Parser/JSON.pm +++ b/lib/SQL/Translator/Parser/JSON.pm @@ -56,6 +56,10 @@ sub parse { for my $cdata ( @{ $tdata->{'constraints'} || [] } ) { $table->add_constraint( %$cdata ) or die $table->error; } + + $table->comments( $tdata->{'comments' } ) + if exists $tdata->{'comments'}; + } # diff --git a/lib/SQL/Translator/Parser/YAML.pm b/lib/SQL/Translator/Parser/YAML.pm index af3b31bb..ea496710 100644 --- a/lib/SQL/Translator/Parser/YAML.pm +++ b/lib/SQL/Translator/Parser/YAML.pm @@ -56,6 +56,9 @@ sub parse { for my $cdata ( @{ $tdata->{'constraints'} || [] } ) { $table->add_constraint( %$cdata ) or die $table->error; } + + $table->comments( $tdata->{'comments' } ) + if exists $tdata->{'comments'}; } # From 09e30d8629368fee84667dea206444b8ddf8c86f Mon Sep 17 00:00:00 2001 From: Diab Jerius Date: Tue, 4 Aug 2015 17:50:18 -0400 Subject: [PATCH 2/2] bugfix: JSON and YAML producers' view_procedure method called comments method in wrong context The JSON and YAML Producer view_procedure methods called the procedure's comments() method in scalar context. However, in scalar context this method returns a string composed of the concatenation of comments. Since the JSON and YAML formats support arrays, their producers should output the comments as arrays to avoid loss of information. This is also consistent with the other calls to comment() elsewhere in the code. --- lib/SQL/Translator/Producer/JSON.pm | 4 ++-- lib/SQL/Translator/Producer/YAML.pm | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/SQL/Translator/Producer/JSON.pm b/lib/SQL/Translator/Producer/JSON.pm index dee6e022..db4a0716 100644 --- a/lib/SQL/Translator/Producer/JSON.pm +++ b/lib/SQL/Translator/Producer/JSON.pm @@ -133,8 +133,8 @@ sub view_procedure { 'sql' => scalar $procedure->sql, 'parameters' => scalar $procedure->parameters, 'owner' => scalar $procedure->owner, - 'comments' => scalar $procedure->comments, - keys %{$procedure->extra} ? ('extra' => { $procedure->extra } ) : (), + $procedure->comments ? ('comments' => [ $procedure->comments ] ) : (), + keys %{$procedure->extra} ? ('extra' => { $procedure->extra } ) : (), }; } diff --git a/lib/SQL/Translator/Producer/YAML.pm b/lib/SQL/Translator/Producer/YAML.pm index bdf4b055..7c7a8fd3 100644 --- a/lib/SQL/Translator/Producer/YAML.pm +++ b/lib/SQL/Translator/Producer/YAML.pm @@ -132,8 +132,8 @@ sub view_procedure { 'sql' => scalar $procedure->sql, 'parameters' => scalar $procedure->parameters, 'owner' => scalar $procedure->owner, - 'comments' => scalar $procedure->comments, - keys %{$procedure->extra} ? ('extra' => { $procedure->extra } ) : (), + $procedure->comments ? ('comments' => [ $procedure->comments ] ) : (), + keys %{$procedure->extra} ? ('extra' => { $procedure->extra } ) : (), }; }