line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SQL::Translator::Parser::YAML; |
2
|
|
|
|
|
|
|
|
3
|
15
|
|
|
15
|
|
112
|
use strict; |
|
15
|
|
|
|
|
43
|
|
|
15
|
|
|
|
|
446
|
|
4
|
15
|
|
|
15
|
|
104
|
use warnings; |
|
15
|
|
|
|
|
46
|
|
|
15
|
|
|
|
|
692
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.63'; |
6
|
|
|
|
|
|
|
|
7
|
15
|
|
|
15
|
|
596
|
use SQL::Translator::Schema; |
|
15
|
|
|
|
|
78
|
|
|
15
|
|
|
|
|
503
|
|
8
|
15
|
|
|
15
|
|
101
|
use SQL::Translator::Utils qw(header_comment); |
|
15
|
|
|
|
|
33
|
|
|
15
|
|
|
|
|
851
|
|
9
|
15
|
|
|
15
|
|
124
|
use Data::Dumper; |
|
15
|
|
|
|
|
61
|
|
|
15
|
|
|
|
|
921
|
|
10
|
15
|
|
|
15
|
|
5471
|
use YAML qw(Load); |
|
15
|
|
|
|
|
84281
|
|
|
15
|
|
|
|
|
12037
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub parse { |
13
|
23
|
|
|
23
|
0
|
83
|
my ($translator, $data) = @_; |
14
|
23
|
|
|
|
|
94
|
$data = Load($data); |
15
|
23
|
|
|
|
|
1829216
|
$data = $data->{'schema'}; |
16
|
|
|
|
|
|
|
|
17
|
23
|
50
|
|
|
|
244
|
warn "YAML data:",Dumper( $data ) if $translator->debug; |
18
|
|
|
|
|
|
|
|
19
|
23
|
|
|
|
|
878
|
my $schema = $translator->schema; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# |
22
|
|
|
|
|
|
|
# Tables |
23
|
|
|
|
|
|
|
# |
24
|
|
|
|
|
|
|
my @tables = |
25
|
59
|
|
|
|
|
185
|
map { $data->{'tables'}{ $_->[1] } } |
26
|
54
|
|
|
|
|
159
|
sort { $a->[0] <=> $b->[0] } |
27
|
59
|
|
100
|
|
|
375
|
map { [ $data->{'tables'}{ $_ }{'order'} || 0, $_ ] } |
28
|
23
|
|
|
|
|
1991
|
keys %{ $data->{'tables'} } |
|
23
|
|
|
|
|
139
|
|
29
|
|
|
|
|
|
|
; |
30
|
|
|
|
|
|
|
|
31
|
23
|
|
|
|
|
185
|
for my $tdata ( @tables ) { |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $table = $schema->add_table( |
34
|
|
|
|
|
|
|
map { |
35
|
59
|
100
|
|
|
|
176
|
$tdata->{$_} ? ($_ => $tdata->{$_}) : () |
|
177
|
50
|
|
|
|
786
|
|
36
|
|
|
|
|
|
|
} (qw/name extra options/) |
37
|
|
|
|
|
|
|
) or die $schema->error; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my @fields = |
40
|
182
|
|
|
|
|
456
|
map { $tdata->{'fields'}{ $_->[1] } } |
41
|
240
|
|
|
|
|
464
|
sort { $a->[0] <=> $b->[0] } |
42
|
182
|
|
|
|
|
719
|
map { [ $tdata->{'fields'}{ $_ }{'order'}, $_ ] } |
43
|
59
|
|
|
|
|
1232
|
keys %{ $tdata->{'fields'} } |
|
59
|
|
|
|
|
341
|
|
44
|
|
|
|
|
|
|
; |
45
|
|
|
|
|
|
|
|
46
|
59
|
|
|
|
|
217
|
for my $fdata ( @fields ) { |
47
|
182
|
50
|
|
|
|
1121
|
$table->add_field( %$fdata ) or die $table->error; |
48
|
|
|
|
|
|
|
$table->primary_key( $fdata->{'name'} ) |
49
|
182
|
100
|
|
|
|
4056
|
if $fdata->{'is_primary_key'}; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
59
|
100
|
|
|
|
155
|
for my $idata ( @{ $tdata->{'indices'} || [] } ) { |
|
59
|
|
|
|
|
348
|
|
53
|
18
|
50
|
|
|
|
135
|
$table->add_index( %$idata ) or die $table->error; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
59
|
100
|
|
|
|
124
|
for my $cdata ( @{ $tdata->{'constraints'} || [] } ) { |
|
59
|
|
|
|
|
247
|
|
57
|
76
|
50
|
|
|
|
497
|
$table->add_constraint( %$cdata ) or die $table->error; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$table->comments( $tdata->{'comments' } ) |
61
|
59
|
50
|
|
|
|
315
|
if exists $tdata->{'comments'}; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# |
65
|
|
|
|
|
|
|
# Views |
66
|
|
|
|
|
|
|
# |
67
|
|
|
|
|
|
|
my @views = |
68
|
2
|
|
|
|
|
11
|
map { $data->{'views'}{ $_->[1] } } |
69
|
0
|
|
|
|
|
0
|
sort { $a->[0] <=> $b->[0] } |
70
|
2
|
|
|
|
|
11
|
map { [ $data->{'views'}{ $_ }{'order'}, $_ ] } |
71
|
23
|
|
|
|
|
91
|
keys %{ $data->{'views'} } |
|
23
|
|
|
|
|
140
|
|
72
|
|
|
|
|
|
|
; |
73
|
|
|
|
|
|
|
|
74
|
23
|
|
|
|
|
83
|
for my $vdata ( @views ) { |
75
|
2
|
50
|
|
|
|
14
|
$schema->add_view( %$vdata ) or die $schema->error; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# |
79
|
|
|
|
|
|
|
# Triggers |
80
|
|
|
|
|
|
|
# |
81
|
|
|
|
|
|
|
my @triggers = |
82
|
6
|
|
|
|
|
19
|
map { $data->{'triggers'}{ $_->[1] } } |
83
|
4
|
|
|
|
|
17
|
sort { $a->[0] <=> $b->[0] } |
84
|
6
|
|
|
|
|
33
|
map { [ $data->{'triggers'}{ $_ }{'order'}, $_ ] } |
85
|
23
|
|
|
|
|
78
|
keys %{ $data->{'triggers'} } |
|
23
|
|
|
|
|
119
|
|
86
|
|
|
|
|
|
|
; |
87
|
|
|
|
|
|
|
|
88
|
23
|
|
|
|
|
72
|
for my $tdata ( @triggers ) { |
89
|
6
|
50
|
|
|
|
34
|
$schema->add_trigger( %$tdata ) or die $schema->error; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# |
93
|
|
|
|
|
|
|
# Procedures |
94
|
|
|
|
|
|
|
# |
95
|
|
|
|
|
|
|
my @procedures = |
96
|
2
|
|
|
|
|
9
|
map { $data->{'procedures'}{ $_->[1] } } |
97
|
0
|
|
|
|
|
0
|
sort { $a->[0] <=> $b->[0] } |
98
|
2
|
|
|
|
|
10
|
map { [ $data->{'procedures'}{ $_ }{'order'}, $_ ] } |
99
|
23
|
|
|
|
|
95
|
keys %{ $data->{'procedures'} } |
|
23
|
|
|
|
|
119
|
|
100
|
|
|
|
|
|
|
; |
101
|
|
|
|
|
|
|
|
102
|
23
|
|
|
|
|
81
|
for my $tdata ( @procedures ) { |
103
|
2
|
50
|
|
|
|
14
|
$schema->add_procedure( %$tdata ) or die $schema->error; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
23
|
50
|
|
|
|
129
|
if ( my $tr_data = $data->{'translator'} ) { |
107
|
0
|
|
|
|
|
0
|
$translator->add_drop_table( $tr_data->{'add_drop_table'} ); |
108
|
0
|
|
|
|
|
0
|
$translator->filename( $tr_data->{'filename'} ); |
109
|
0
|
|
|
|
|
0
|
$translator->no_comments( $tr_data->{'no_comments'} ); |
110
|
0
|
|
|
|
|
0
|
$translator->parser_args( $tr_data->{'parser_args'} ); |
111
|
0
|
|
|
|
|
0
|
$translator->producer_args( $tr_data->{'producer_args'} ); |
112
|
0
|
|
|
|
|
0
|
$translator->parser_type( $tr_data->{'parser_type'} ); |
113
|
0
|
|
|
|
|
0
|
$translator->producer_type( $tr_data->{'producer_type'} ); |
114
|
0
|
|
|
|
|
0
|
$translator->show_warnings( $tr_data->{'show_warnings'} ); |
115
|
0
|
|
|
|
|
0
|
$translator->trace( $tr_data->{'trace'} ); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
23
|
|
|
|
|
653
|
return 1; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__END__ |