From: Dagfinn Ilmari Mannsåker Date: Tue, 8 Sep 2015 17:04:42 +0000 (+0100) Subject: Fix multi-line comments in YAML and JSON producers X-Git-Tag: v0.11022~23 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=99fa843eca73931cb10225f08d24190ae9a2fc87;p=dbsrgits%2FSQL-Translator.git Fix multi-line comments in YAML and JSON producers --- diff --git a/Changes b/Changes index 0e43239..4d36f95 100644 --- a/Changes +++ b/Changes @@ -14,6 +14,7 @@ Changes for SQL::Translator * Fix parsing of strings with leading whitespace for MySQL, Oracle, PostgreSQL, SQLServer and SQLite * Fix parsing of MySQL column comments (RT#83380) + * Fix multi-line comments in YAML and JSON producers 0.11021 2015-01-29 diff --git a/lib/SQL/Translator/Producer/JSON.pm b/lib/SQL/Translator/Producer/JSON.pm index 0095316..890a958 100644 --- a/lib/SQL/Translator/Producer/JSON.pm +++ b/lib/SQL/Translator/Producer/JSON.pm @@ -72,7 +72,7 @@ sub view_table { 'name' => $table->name, 'order' => $table->order, 'options' => $table->options || [], - $table->comments ? ('comments' => $table->comments ) : (), + $table->comments ? ('comments' => [ $table->comments ] ) : (), 'constraints' => [ map { view_constraint($_) } $table->get_constraints ], @@ -119,7 +119,7 @@ sub view_field { 'is_primary_key' => scalar $field->is_primary_key, 'is_unique' => scalar $field->is_unique, $field->is_auto_increment ? ('is_auto_increment' => 1) : (), - $field->comments ? ('comments' => $field->comments) : (), + $field->comments ? ('comments' => [ $field->comments ]) : (), keys %{$field->extra} ? ('extra' => { $field->extra } ) : (), }; } diff --git a/lib/SQL/Translator/Producer/YAML.pm b/lib/SQL/Translator/Producer/YAML.pm index 177cbdf..49d7029 100644 --- a/lib/SQL/Translator/Producer/YAML.pm +++ b/lib/SQL/Translator/Producer/YAML.pm @@ -71,7 +71,7 @@ sub view_table { 'name' => $table->name, 'order' => $table->order, 'options' => $table->options || [], - $table->comments ? ('comments' => $table->comments ) : (), + $table->comments ? ('comments' => [ $table->comments ] ) : (), 'constraints' => [ map { view_constraint($_) } $table->get_constraints ], @@ -118,7 +118,7 @@ sub view_field { 'is_primary_key' => scalar $field->is_primary_key, 'is_unique' => scalar $field->is_unique, $field->is_auto_increment ? ('is_auto_increment' => 1) : (), - $field->comments ? ('comments' => $field->comments) : (), + $field->comments ? ('comments' => [ $field->comments ]) : (), keys %{$field->extra} ? ('extra' => { $field->extra } ) : (), }; } diff --git a/t/23json.t b/t/23json.t index 0b063e2..cfc721c 100644 --- a/t/23json.t +++ b/t/23json.t @@ -104,6 +104,10 @@ my $json = to_json(from_json(< 1, pretty => 1 }); ] }, "person_id" : { + "comments" : [ + "field comment 1", + "field comment 2" + ], "data_type" : "INTEGER", "default_value" : null, "is_auto_increment" : 1, diff --git a/t/24yaml.t b/t/24yaml.t index 08757d9..e177907 100644 --- a/t/24yaml.t +++ b/t/24yaml.t @@ -87,6 +87,9 @@ schema: size: - 20 person_id: + comments: + - field comment 1 + - field comment 2 data_type: INTEGER default_value: ~ is_auto_increment: 1 diff --git a/t/data/sqlite/create.sql b/t/data/sqlite/create.sql index f7a397f..56f1153 100644 --- a/t/data/sqlite/create.sql +++ b/t/data/sqlite/create.sql @@ -1,4 +1,6 @@ create table person ( + -- field comment 1 + -- field comment 2 person_id INTEGER PRIMARY KEY AUTOINCREMENT, 'name' varchar(20) not null, 'age' integer,