line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SQL::Translator::Parser::YAML; |
2
|
|
|
|
|
|
|
|
3
|
15
|
|
|
15
|
|
116
|
use strict; |
|
15
|
|
|
|
|
37
|
|
|
15
|
|
|
|
|
504
|
|
4
|
15
|
|
|
15
|
|
85
|
use warnings; |
|
15
|
|
|
|
|
37
|
|
|
15
|
|
|
|
|
859
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.62'; |
6
|
|
|
|
|
|
|
|
7
|
15
|
|
|
15
|
|
659
|
use SQL::Translator::Schema; |
|
15
|
|
|
|
|
37
|
|
|
15
|
|
|
|
|
504
|
|
8
|
15
|
|
|
15
|
|
110
|
use SQL::Translator::Utils qw(header_comment); |
|
15
|
|
|
|
|
43
|
|
|
15
|
|
|
|
|
920
|
|
9
|
15
|
|
|
15
|
|
105
|
use Data::Dumper; |
|
15
|
|
|
|
|
34
|
|
|
15
|
|
|
|
|
931
|
|
10
|
15
|
|
|
15
|
|
5893
|
use YAML qw(Load); |
|
15
|
|
|
|
|
86924
|
|
|
15
|
|
|
|
|
12438
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub parse { |
13
|
22
|
|
|
22
|
0
|
68
|
my ($translator, $data) = @_; |
14
|
22
|
|
|
|
|
100
|
$data = Load($data); |
15
|
22
|
|
|
|
|
1890924
|
$data = $data->{'schema'}; |
16
|
|
|
|
|
|
|
|
17
|
22
|
50
|
|
|
|
256
|
warn "YAML data:",Dumper( $data ) if $translator->debug; |
18
|
|
|
|
|
|
|
|
19
|
22
|
|
|
|
|
754
|
my $schema = $translator->schema; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# |
22
|
|
|
|
|
|
|
# Tables |
23
|
|
|
|
|
|
|
# |
24
|
|
|
|
|
|
|
my @tables = |
25
|
58
|
|
|
|
|
180
|
map { $data->{'tables'}{ $_->[1] } } |
26
|
54
|
|
|
|
|
153
|
sort { $a->[0] <=> $b->[0] } |
27
|
58
|
|
100
|
|
|
351
|
map { [ $data->{'tables'}{ $_ }{'order'} || 0, $_ ] } |
28
|
22
|
|
|
|
|
1725
|
keys %{ $data->{'tables'} } |
|
22
|
|
|
|
|
125
|
|
29
|
|
|
|
|
|
|
; |
30
|
|
|
|
|
|
|
|
31
|
22
|
|
|
|
|
109
|
for my $tdata ( @tables ) { |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $table = $schema->add_table( |
34
|
|
|
|
|
|
|
map { |
35
|
58
|
100
|
|
|
|
157
|
$tdata->{$_} ? ($_ => $tdata->{$_}) : () |
|
174
|
50
|
|
|
|
788
|
|
36
|
|
|
|
|
|
|
} (qw/name extra options/) |
37
|
|
|
|
|
|
|
) or die $schema->error; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my @fields = |
40
|
178
|
|
|
|
|
451
|
map { $tdata->{'fields'}{ $_->[1] } } |
41
|
232
|
|
|
|
|
441
|
sort { $a->[0] <=> $b->[0] } |
42
|
178
|
|
|
|
|
703
|
map { [ $tdata->{'fields'}{ $_ }{'order'}, $_ ] } |
43
|
58
|
|
|
|
|
1201
|
keys %{ $tdata->{'fields'} } |
|
58
|
|
|
|
|
338
|
|
44
|
|
|
|
|
|
|
; |
45
|
|
|
|
|
|
|
|
46
|
58
|
|
|
|
|
252
|
for my $fdata ( @fields ) { |
47
|
178
|
50
|
|
|
|
1143
|
$table->add_field( %$fdata ) or die $table->error; |
48
|
|
|
|
|
|
|
$table->primary_key( $fdata->{'name'} ) |
49
|
178
|
100
|
|
|
|
3989
|
if $fdata->{'is_primary_key'}; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
58
|
100
|
|
|
|
146
|
for my $idata ( @{ $tdata->{'indices'} || [] } ) { |
|
58
|
|
|
|
|
314
|
|
53
|
19
|
50
|
|
|
|
162
|
$table->add_index( %$idata ) or die $table->error; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
58
|
100
|
|
|
|
123
|
for my $cdata ( @{ $tdata->{'constraints'} || [] } ) { |
|
58
|
|
|
|
|
283
|
|
57
|
74
|
50
|
|
|
|
499
|
$table->add_constraint( %$cdata ) or die $table->error; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# |
62
|
|
|
|
|
|
|
# Views |
63
|
|
|
|
|
|
|
# |
64
|
|
|
|
|
|
|
my @views = |
65
|
3
|
|
|
|
|
19
|
map { $data->{'views'}{ $_->[1] } } |
66
|
0
|
|
|
|
|
0
|
sort { $a->[0] <=> $b->[0] } |
67
|
3
|
|
|
|
|
25
|
map { [ $data->{'views'}{ $_ }{'order'}, $_ ] } |
68
|
22
|
|
|
|
|
80
|
keys %{ $data->{'views'} } |
|
22
|
|
|
|
|
139
|
|
69
|
|
|
|
|
|
|
; |
70
|
|
|
|
|
|
|
|
71
|
22
|
|
|
|
|
89
|
for my $vdata ( @views ) { |
72
|
3
|
50
|
|
|
|
24
|
$schema->add_view( %$vdata ) or die $schema->error; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# |
76
|
|
|
|
|
|
|
# Triggers |
77
|
|
|
|
|
|
|
# |
78
|
|
|
|
|
|
|
my @triggers = |
79
|
9
|
|
|
|
|
23
|
map { $data->{'triggers'}{ $_->[1] } } |
80
|
9
|
|
|
|
|
30
|
sort { $a->[0] <=> $b->[0] } |
81
|
9
|
|
|
|
|
42
|
map { [ $data->{'triggers'}{ $_ }{'order'}, $_ ] } |
82
|
22
|
|
|
|
|
59
|
keys %{ $data->{'triggers'} } |
|
22
|
|
|
|
|
134
|
|
83
|
|
|
|
|
|
|
; |
84
|
|
|
|
|
|
|
|
85
|
22
|
|
|
|
|
81
|
for my $tdata ( @triggers ) { |
86
|
9
|
50
|
|
|
|
58
|
$schema->add_trigger( %$tdata ) or die $schema->error; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# |
90
|
|
|
|
|
|
|
# Procedures |
91
|
|
|
|
|
|
|
# |
92
|
|
|
|
|
|
|
my @procedures = |
93
|
3
|
|
|
|
|
17
|
map { $data->{'procedures'}{ $_->[1] } } |
94
|
0
|
|
|
|
|
0
|
sort { $a->[0] <=> $b->[0] } |
95
|
3
|
|
|
|
|
20
|
map { [ $data->{'procedures'}{ $_ }{'order'}, $_ ] } |
96
|
22
|
|
|
|
|
54
|
keys %{ $data->{'procedures'} } |
|
22
|
|
|
|
|
117
|
|
97
|
|
|
|
|
|
|
; |
98
|
|
|
|
|
|
|
|
99
|
22
|
|
|
|
|
98
|
for my $tdata ( @procedures ) { |
100
|
3
|
50
|
|
|
|
28
|
$schema->add_procedure( %$tdata ) or die $schema->error; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
22
|
50
|
|
|
|
117
|
if ( my $tr_data = $data->{'translator'} ) { |
104
|
0
|
|
|
|
|
0
|
$translator->add_drop_table( $tr_data->{'add_drop_table'} ); |
105
|
0
|
|
|
|
|
0
|
$translator->filename( $tr_data->{'filename'} ); |
106
|
0
|
|
|
|
|
0
|
$translator->no_comments( $tr_data->{'no_comments'} ); |
107
|
0
|
|
|
|
|
0
|
$translator->parser_args( $tr_data->{'parser_args'} ); |
108
|
0
|
|
|
|
|
0
|
$translator->producer_args( $tr_data->{'producer_args'} ); |
109
|
0
|
|
|
|
|
0
|
$translator->parser_type( $tr_data->{'parser_type'} ); |
110
|
0
|
|
|
|
|
0
|
$translator->producer_type( $tr_data->{'producer_type'} ); |
111
|
0
|
|
|
|
|
0
|
$translator->show_warnings( $tr_data->{'show_warnings'} ); |
112
|
0
|
|
|
|
|
0
|
$translator->trace( $tr_data->{'trace'} ); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
22
|
|
|
|
|
699
|
return 1; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |