From: Peter Rabbitson Date: Tue, 9 Jun 2009 20:45:34 +0000 (+0000) Subject: Teach YAML producer to encode extra attributes X-Git-Tag: v0.11008~158 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=00db1ad50a7fc9696272ca554ea63ac4f03e3b49;p=dbsrgits%2FSQL-Translator.git Teach YAML producer to encode extra attributes --- diff --git a/lib/SQL/Translator/Producer/YAML.pm b/lib/SQL/Translator/Producer/YAML.pm index 7970a61..688d7a8 100644 --- a/lib/SQL/Translator/Producer/YAML.pm +++ b/lib/SQL/Translator/Producer/YAML.pm @@ -78,7 +78,8 @@ sub produce { show_warnings => $translator->show_warnings, trace => $translator->trace, version => $translator->version, - } + }, + keys %{$schema->extra} ? ('extra' => { $schema->extra } ) : (), }); } @@ -101,6 +102,7 @@ sub view_table { map { ($_->name => view_field($_)) } $table->get_fields }, + keys %{$table->extra} ? ('extra' => { $table->extra } ) : (), }; } @@ -117,9 +119,10 @@ sub view_constraint { 'options' => scalar $constraint->options, 'on_delete' => scalar $constraint->on_delete, 'on_update' => scalar $constraint->on_update, - 'reference_fields' => scalar $constraint->reference_fields, + 'reference_fields' => [ map { ref $_ ? $_->name : $_ } $constraint->reference_fields ], 'reference_table' => scalar $constraint->reference_table, 'type' => scalar $constraint->type, + keys %{$constraint->extra} ? ('extra' => { $constraint->extra } ) : (), }; } @@ -138,7 +141,7 @@ sub view_field { 'is_unique' => scalar $field->is_unique, $field->is_auto_increment ? ('is_auto_increment' => 1) : (), $field->comments ? ('comments' => $field->comments) : (), - 'extra' => { $field->extra }, + keys %{$field->extra} ? ('extra' => { $field->extra } ) : (), }; } @@ -153,6 +156,7 @@ sub view_procedure { 'parameters' => scalar $procedure->parameters, 'owner' => scalar $procedure->owner, 'comments' => scalar $procedure->comments, + keys %{$procedure->extra} ? ('extra' => { $procedure->extra } ) : (), }; } @@ -168,6 +172,7 @@ sub view_trigger { 'fields' => scalar $trigger->fields, 'on_table' => scalar $trigger->on_table, 'action' => scalar $trigger->action, + keys %{$trigger->extra} ? ('extra' => { $trigger->extra } ) : (), }; } @@ -180,6 +185,7 @@ sub view_view { 'name' => scalar $view->name, 'sql' => scalar $view->sql, 'fields' => scalar $view->fields, + keys %{$view->extra} ? ('extra' => { $view->extra } ) : (), }; } @@ -192,6 +198,7 @@ sub view_index { 'type' => scalar $index->type, 'fields' => scalar $index->fields, 'options' => scalar $index->options, + keys %{$index->extra} ? ('extra' => { $index->extra } ) : (), }; } diff --git a/t/24yaml.t b/t/24yaml.t index 9f9f2c7..9c8bda3 100644 --- a/t/24yaml.t +++ b/t/24yaml.t @@ -1,6 +1,4 @@ -#!/usr/local/bin/perl -# vim: set ft=perl: - +use warnings; use strict; use Test::More; use Test::Differences; @@ -50,7 +48,6 @@ schema: age: data_type: integer default_value: ~ - extra: {} is_nullable: 1 is_primary_key: 0 is_unique: 0 @@ -61,7 +58,6 @@ schema: description: data_type: text default_value: ~ - extra: {} is_nullable: 1 is_primary_key: 0 is_unique: 0 @@ -72,7 +68,6 @@ schema: iq: data_type: tinyint default_value: 0 - extra: {} is_nullable: 1 is_primary_key: 0 is_unique: 0 @@ -83,7 +78,6 @@ schema: name: data_type: varchar default_value: ~ - extra: {} is_nullable: 0 is_primary_key: 0 is_unique: 1 @@ -94,7 +88,6 @@ schema: person_id: data_type: INTEGER default_value: ~ - extra: {} is_nullable: 0 is_primary_key: 1 is_unique: 0 @@ -105,7 +98,6 @@ schema: weight: data_type: double default_value: ~ - extra: {} is_nullable: 1 is_primary_key: 0 is_unique: 0 @@ -148,7 +140,6 @@ schema: age: data_type: int default_value: ~ - extra: {} is_nullable: 1 is_primary_key: 0 is_unique: 0 @@ -159,7 +150,6 @@ schema: name: data_type: varchar default_value: ~ - extra: {} is_nullable: 1 is_primary_key: 0 is_unique: 0 @@ -170,7 +160,6 @@ schema: person_id: data_type: int default_value: ~ - extra: {} is_nullable: 0 is_primary_key: 1 is_unique: 0 @@ -181,7 +170,6 @@ schema: pet_id: data_type: int default_value: ~ - extra: {} is_nullable: 0 is_primary_key: 1 is_unique: 0 diff --git a/t/36-filters.t b/t/36-filters.t index c1aee85..15da914 100644 --- a/t/36-filters.t +++ b/t/36-filters.t @@ -83,7 +83,6 @@ schema: first_name: data_type: foovar default_value: ~ - extra: {} is_nullable: 1 is_primary_key: 0 is_unique: 0 diff --git a/t/38-filter-names.t b/t/38-filter-names.t index d35999e..47428b4 100644 --- a/t/38-filter-names.t +++ b/t/38-filter-names.t @@ -38,7 +38,6 @@ schema: First_name: data_type: foovar default_value: ~ - extra: {} is_nullable: 1 is_primary_key: 0 is_unique: 0 diff --git a/t/39-filter-globals.t b/t/39-filter-globals.t index 2a7636d..0b77e62 100644 --- a/t/39-filter-globals.t +++ b/t/39-filter-globals.t @@ -69,7 +69,6 @@ schema: created: data_type: timestamp default_value: ~ - extra: {} is_nullable: 0 is_primary_key: 0 is_unique: 0 @@ -80,7 +79,6 @@ schema: first_name: data_type: foovar default_value: ~ - extra: {} is_nullable: 1 is_primary_key: 0 is_unique: 0 @@ -91,7 +89,6 @@ schema: modified: data_type: timestamp default_value: ~ - extra: {} is_nullable: 1 is_primary_key: 0 is_unique: 1