1 package SQL::Translator::Parser::YAML;
7 use SQL::Translator::Schema;
8 use SQL::Translator::Utils qw(header_comment);
13 my ($translator, $data) = @_;
15 $data = $data->{'schema'};
17 warn "YAML data:",Dumper( $data ) if $translator->debug;
19 my $schema = $translator->schema;
25 map { $data->{'tables'}{ $_->[1] } }
26 sort { $a->[0] <=> $b->[0] }
27 map { [ $data->{'tables'}{ $_ }{'order'} || 0, $_ ] }
28 keys %{ $data->{'tables'} }
31 for my $tdata ( @tables ) {
33 my $table = $schema->add_table(
35 $tdata->{$_} ? ($_ => $tdata->{$_}) : ()
36 } (qw/name extra options/)
37 ) or die $schema->error;
40 map { $tdata->{'fields'}{ $_->[1] } }
41 sort { $a->[0] <=> $b->[0] }
42 map { [ $tdata->{'fields'}{ $_ }{'order'}, $_ ] }
43 keys %{ $tdata->{'fields'} }
46 for my $fdata ( @fields ) {
47 $table->add_field( %$fdata ) or die $table->error;
48 $table->primary_key( $fdata->{'name'} )
49 if $fdata->{'is_primary_key'};
52 for my $idata ( @{ $tdata->{'indices'} || [] } ) {
53 $table->add_index( %$idata ) or die $table->error;
56 for my $cdata ( @{ $tdata->{'constraints'} || [] } ) {
57 $table->add_constraint( %$cdata ) or die $table->error;
65 map { $data->{'views'}{ $_->[1] } }
66 sort { $a->[0] <=> $b->[0] }
67 map { [ $data->{'views'}{ $_ }{'order'}, $_ ] }
68 keys %{ $data->{'views'} }
71 for my $vdata ( @views ) {
72 $schema->add_view( %$vdata ) or die $schema->error;
79 map { $data->{'triggers'}{ $_->[1] } }
80 sort { $a->[0] <=> $b->[0] }
81 map { [ $data->{'triggers'}{ $_ }{'order'}, $_ ] }
82 keys %{ $data->{'triggers'} }
85 for my $tdata ( @triggers ) {
86 $schema->add_trigger( %$tdata ) or die $schema->error;
93 map { $data->{'procedures'}{ $_->[1] } }
94 sort { $a->[0] <=> $b->[0] }
95 map { [ $data->{'procedures'}{ $_ }{'order'}, $_ ] }
96 keys %{ $data->{'procedures'} }
99 for my $tdata ( @procedures ) {
100 $schema->add_procedure( %$tdata ) or die $schema->error;
103 if ( my $tr_data = $data->{'translator'} ) {
104 $translator->add_drop_table( $tr_data->{'add_drop_table'} );
105 $translator->filename( $tr_data->{'filename'} );
106 $translator->no_comments( $tr_data->{'no_comments'} );
107 $translator->parser_args( $tr_data->{'parser_args'} );
108 $translator->producer_args( $tr_data->{'producer_args'} );
109 $translator->parser_type( $tr_data->{'parser_type'} );
110 $translator->producer_type( $tr_data->{'producer_type'} );
111 $translator->show_warnings( $tr_data->{'show_warnings'} );
112 $translator->trace( $tr_data->{'trace'} );
124 SQL::Translator::Parser::YAML - Parse a YAML representation of a schema
130 my $translator = SQL::Translator->new(parser => "YAML");
134 C<SQL::Translator::Parser::YAML> parses a schema serialized with YAML.
138 Darren Chamberlain E<lt>darren@cpan.orgE<gt>,
139 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>.