Made some changes suggested by Michael Slattery to fix table level comments. Also...
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Parser / YAML.pm
index f00b8d3..028d4d1 100644 (file)
@@ -1,10 +1,9 @@
 package SQL::Translator::Parser::YAML;
 
 # -------------------------------------------------------------------
-# $Id: YAML.pm,v 1.2 2003-10-08 22:44:52 kycl4rk Exp $
+# $Id: YAML.pm,v 1.7 2005-06-08 11:30:15 grommit Exp $
 # -------------------------------------------------------------------
-# Copyright (C) 2003 darren chamberlain <darren@cpan.org>,
-#   Ken Y. Clark <kclark@cpan.org>.
+# Copyright (C) 2002-4 SQLFairy Authors
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -23,7 +22,7 @@ package SQL::Translator::Parser::YAML;
 
 use strict;
 use vars qw($VERSION);
-$VERSION = sprintf "%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/;
 
 use SQL::Translator::Schema;
 use SQL::Translator::Utils qw(header_comment);
@@ -35,7 +34,7 @@ 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;
 
@@ -52,6 +51,7 @@ sub parse {
     for my $tdata ( @tables ) {
         my $table = $schema->add_table(
             name  => $tdata->{'name'},
+            extra => $tdata->{'extra'},
         ) or die $schema->error;
 
         my @fields = 
@@ -63,6 +63,16 @@ sub parse {
 
         for my $fdata ( @fields ) {
             $table->add_field( %$fdata ) or die $table->error;
+            $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;
         }
     }
 
@@ -108,6 +118,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;
 }
 
@@ -129,7 +151,7 @@ SQL::Translator::Parser::YAML - Parse a YAML representation of a schema
 
 C<SQL::Translator::Parser::YAML> parses a schema serialized with YAML.
 
-=head1 AUTHOR
+=head1 AUTHORS
 
 Darren Chamberlain E<lt>darren@cpan.orgE<gt>,
 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>.