X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FParser%2FYAML.pm;h=462ddcde8c760fb3e57887eb6cdb7241ae7501c3;hb=0c04c5a2210135419771878dc7e341a1cba52cca;hp=e0ee2eae909f261e20e5cdf3d5a15dccf890831c;hpb=46a063501073ea2469bcd204c68c6a546974df13;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Parser/YAML.pm b/lib/SQL/Translator/Parser/YAML.pm index e0ee2ea..462ddcd 100644 --- a/lib/SQL/Translator/Parser/YAML.pm +++ b/lib/SQL/Translator/Parser/YAML.pm @@ -1,29 +1,8 @@ package SQL::Translator::Parser::YAML; -# ------------------------------------------------------------------- -# $Id: YAML.pm,v 1.3 2003-10-09 21:48:55 kycl4rk Exp $ -# ------------------------------------------------------------------- -# Copyright (C) 2003 darren chamberlain , -# Ken Y. Clark . -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; version 2. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -# 02111-1307 USA -# ------------------------------------------------------------------- - use strict; -use vars qw($VERSION); -$VERSION = sprintf "%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/; +use warnings; +our $VERSION = '1.59'; use SQL::Translator::Schema; use SQL::Translator::Utils qw(header_comment); @@ -35,26 +14,29 @@ sub parse { $data = Load($data); $data = $data->{'schema'}; - warn Dumper( $data ) if $translator->debug; + warn "YAML data:",Dumper( $data ) if $translator->debug; my $schema = $translator->schema; # # Tables # - my @tables = + my @tables = map { $data->{'tables'}{ $_->[1] } } sort { $a->[0] <=> $b->[0] } - map { [ $data->{'tables'}{ $_ }{'order'}, $_ ] } + map { [ $data->{'tables'}{ $_ }{'order'} || 0, $_ ] } keys %{ $data->{'tables'} } ; for my $tdata ( @tables ) { + my $table = $schema->add_table( - name => $tdata->{'name'}, + map { + $tdata->{$_} ? ($_ => $tdata->{$_}) : () + } (qw/name extra options/) ) or die $schema->error; - my @fields = + my @fields = map { $tdata->{'fields'}{ $_->[1] } } sort { $a->[0] <=> $b->[0] } map { [ $tdata->{'fields'}{ $_ }{'order'}, $_ ] } @@ -63,15 +45,23 @@ sub parse { for my $fdata ( @fields ) { $table->add_field( %$fdata ) or die $table->error; - $table->primary_key( $fdata->{'name'} ) + $table->primary_key( $fdata->{'name'} ) if $fdata->{'is_primary_key'}; } + + for my $idata ( @{ $tdata->{'indices'} || [] } ) { + $table->add_index( %$idata ) or die $table->error; + } + + for my $cdata ( @{ $tdata->{'constraints'} || [] } ) { + $table->add_constraint( %$cdata ) or die $table->error; + } } # # Views # - my @views = + my @views = map { $data->{'views'}{ $_->[1] } } sort { $a->[0] <=> $b->[0] } map { [ $data->{'views'}{ $_ }{'order'}, $_ ] } @@ -85,7 +75,7 @@ sub parse { # # Triggers # - my @triggers = + my @triggers = map { $data->{'triggers'}{ $_->[1] } } sort { $a->[0] <=> $b->[0] } map { [ $data->{'triggers'}{ $_ }{'order'}, $_ ] } @@ -99,7 +89,7 @@ sub parse { # # Procedures # - my @procedures = + my @procedures = map { $data->{'procedures'}{ $_->[1] } } sort { $a->[0] <=> $b->[0] } map { [ $data->{'procedures'}{ $_ }{'order'}, $_ ] } @@ -110,6 +100,18 @@ sub parse { $schema->add_procedure( %$tdata ) or die $schema->error; } + if ( my $tr_data = $data->{'translator'} ) { + $translator->add_drop_table( $tr_data->{'add_drop_table'} ); + $translator->filename( $tr_data->{'filename'} ); + $translator->no_comments( $tr_data->{'no_comments'} ); + $translator->parser_args( $tr_data->{'parser_args'} ); + $translator->producer_args( $tr_data->{'producer_args'} ); + $translator->parser_type( $tr_data->{'parser_type'} ); + $translator->producer_type( $tr_data->{'producer_type'} ); + $translator->show_warnings( $tr_data->{'show_warnings'} ); + $translator->trace( $tr_data->{'trace'} ); + } + return 1; } @@ -131,7 +133,7 @@ SQL::Translator::Parser::YAML - Parse a YAML representation of a schema C parses a schema serialized with YAML. -=head1 AUTHOR +=head1 AUTHORS Darren Chamberlain Edarren@cpan.orgE, Ken Y. Clark Ekclark@cpan.orgE.