line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SQL::Translator::Parser::YAML; |
2
|
|
|
|
|
|
|
|
3
|
15
|
|
|
15
|
|
96
|
use strict; |
|
15
|
|
|
|
|
28
|
|
|
15
|
|
|
|
|
404
|
|
4
|
15
|
|
|
15
|
|
72
|
use warnings; |
|
15
|
|
|
|
|
26
|
|
|
15
|
|
|
|
|
628
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.6_3'; |
6
|
|
|
|
|
|
|
|
7
|
15
|
|
|
15
|
|
467
|
use SQL::Translator::Schema; |
|
15
|
|
|
|
|
30
|
|
|
15
|
|
|
|
|
490
|
|
8
|
15
|
|
|
15
|
|
82
|
use SQL::Translator::Utils qw(header_comment); |
|
15
|
|
|
|
|
28
|
|
|
15
|
|
|
|
|
788
|
|
9
|
15
|
|
|
15
|
|
90
|
use Data::Dumper; |
|
15
|
|
|
|
|
32
|
|
|
15
|
|
|
|
|
671
|
|
10
|
15
|
|
|
15
|
|
4516
|
use YAML qw(Load); |
|
15
|
|
|
|
|
71501
|
|
|
15
|
|
|
|
|
10174
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub parse { |
13
|
22
|
|
|
22
|
0
|
73
|
my ($translator, $data) = @_; |
14
|
22
|
|
|
|
|
95
|
$data = Load($data); |
15
|
22
|
|
|
|
|
1551164
|
$data = $data->{'schema'}; |
16
|
|
|
|
|
|
|
|
17
|
22
|
50
|
|
|
|
212
|
warn "YAML data:",Dumper( $data ) if $translator->debug; |
18
|
|
|
|
|
|
|
|
19
|
22
|
|
|
|
|
627
|
my $schema = $translator->schema; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# |
22
|
|
|
|
|
|
|
# Tables |
23
|
|
|
|
|
|
|
# |
24
|
|
|
|
|
|
|
my @tables = |
25
|
58
|
|
|
|
|
149
|
map { $data->{'tables'}{ $_->[1] } } |
26
|
55
|
|
|
|
|
131
|
sort { $a->[0] <=> $b->[0] } |
27
|
58
|
|
100
|
|
|
289
|
map { [ $data->{'tables'}{ $_ }{'order'} || 0, $_ ] } |
28
|
22
|
|
|
|
|
1414
|
keys %{ $data->{'tables'} } |
|
22
|
|
|
|
|
111
|
|
29
|
|
|
|
|
|
|
; |
30
|
|
|
|
|
|
|
|
31
|
22
|
|
|
|
|
88
|
for my $tdata ( @tables ) { |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $table = $schema->add_table( |
34
|
|
|
|
|
|
|
map { |
35
|
58
|
100
|
|
|
|
160
|
$tdata->{$_} ? ($_ => $tdata->{$_}) : () |
|
174
|
50
|
|
|
|
708
|
|
36
|
|
|
|
|
|
|
} (qw/name extra options/) |
37
|
|
|
|
|
|
|
) or die $schema->error; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my @fields = |
40
|
178
|
|
|
|
|
363
|
map { $tdata->{'fields'}{ $_->[1] } } |
41
|
241
|
|
|
|
|
389
|
sort { $a->[0] <=> $b->[0] } |
42
|
178
|
|
|
|
|
570
|
map { [ $tdata->{'fields'}{ $_ }{'order'}, $_ ] } |
43
|
58
|
|
|
|
|
992
|
keys %{ $tdata->{'fields'} } |
|
58
|
|
|
|
|
269
|
|
44
|
|
|
|
|
|
|
; |
45
|
|
|
|
|
|
|
|
46
|
58
|
|
|
|
|
184
|
for my $fdata ( @fields ) { |
47
|
178
|
50
|
|
|
|
994
|
$table->add_field( %$fdata ) or die $table->error; |
48
|
|
|
|
|
|
|
$table->primary_key( $fdata->{'name'} ) |
49
|
178
|
100
|
|
|
|
3315
|
if $fdata->{'is_primary_key'}; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
58
|
100
|
|
|
|
131
|
for my $idata ( @{ $tdata->{'indices'} || [] } ) { |
|
58
|
|
|
|
|
293
|
|
53
|
19
|
50
|
|
|
|
132
|
$table->add_index( %$idata ) or die $table->error; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
58
|
100
|
|
|
|
139
|
for my $cdata ( @{ $tdata->{'constraints'} || [] } ) { |
|
58
|
|
|
|
|
243
|
|
57
|
74
|
50
|
|
|
|
458
|
$table->add_constraint( %$cdata ) or die $table->error; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# |
62
|
|
|
|
|
|
|
# Views |
63
|
|
|
|
|
|
|
# |
64
|
|
|
|
|
|
|
my @views = |
65
|
3
|
|
|
|
|
13
|
map { $data->{'views'}{ $_->[1] } } |
66
|
0
|
|
|
|
|
0
|
sort { $a->[0] <=> $b->[0] } |
67
|
3
|
|
|
|
|
14
|
map { [ $data->{'views'}{ $_ }{'order'}, $_ ] } |
68
|
22
|
|
|
|
|
58
|
keys %{ $data->{'views'} } |
|
22
|
|
|
|
|
116
|
|
69
|
|
|
|
|
|
|
; |
70
|
|
|
|
|
|
|
|
71
|
22
|
|
|
|
|
73
|
for my $vdata ( @views ) { |
72
|
3
|
50
|
|
|
|
20
|
$schema->add_view( %$vdata ) or die $schema->error; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# |
76
|
|
|
|
|
|
|
# Triggers |
77
|
|
|
|
|
|
|
# |
78
|
|
|
|
|
|
|
my @triggers = |
79
|
9
|
|
|
|
|
19
|
map { $data->{'triggers'}{ $_->[1] } } |
80
|
8
|
|
|
|
|
21
|
sort { $a->[0] <=> $b->[0] } |
81
|
9
|
|
|
|
|
39
|
map { [ $data->{'triggers'}{ $_ }{'order'}, $_ ] } |
82
|
22
|
|
|
|
|
51
|
keys %{ $data->{'triggers'} } |
|
22
|
|
|
|
|
94
|
|
83
|
|
|
|
|
|
|
; |
84
|
|
|
|
|
|
|
|
85
|
22
|
|
|
|
|
61
|
for my $tdata ( @triggers ) { |
86
|
9
|
50
|
|
|
|
44
|
$schema->add_trigger( %$tdata ) or die $schema->error; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# |
90
|
|
|
|
|
|
|
# Procedures |
91
|
|
|
|
|
|
|
# |
92
|
|
|
|
|
|
|
my @procedures = |
93
|
3
|
|
|
|
|
12
|
map { $data->{'procedures'}{ $_->[1] } } |
94
|
0
|
|
|
|
|
0
|
sort { $a->[0] <=> $b->[0] } |
95
|
3
|
|
|
|
|
15
|
map { [ $data->{'procedures'}{ $_ }{'order'}, $_ ] } |
96
|
22
|
|
|
|
|
46
|
keys %{ $data->{'procedures'} } |
|
22
|
|
|
|
|
94
|
|
97
|
|
|
|
|
|
|
; |
98
|
|
|
|
|
|
|
|
99
|
22
|
|
|
|
|
57
|
for my $tdata ( @procedures ) { |
100
|
3
|
50
|
|
|
|
21
|
$schema->add_procedure( %$tdata ) or die $schema->error; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
22
|
50
|
|
|
|
109
|
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
|
|
|
|
|
638
|
return 1; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |