line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SQL::Translator::Producer::YAML; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
SQL::Translator::Producer::YAML - A YAML producer for SQL::Translator |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use SQL::Translator; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $translator = SQL::Translator->new(producer => 'YAML'); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
This module uses YAML to serialize a schema to a string so that it |
16
|
|
|
|
|
|
|
can be saved to disk. Serializing a schema and then calling producers |
17
|
|
|
|
|
|
|
on the stored can realize significant performance gains when parsing |
18
|
|
|
|
|
|
|
takes a long time. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
5
|
|
|
5
|
|
2788
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
135
|
|
23
|
5
|
|
|
5
|
|
22
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
196
|
|
24
|
|
|
|
|
|
|
our $VERSION = '1.6_3'; |
25
|
|
|
|
|
|
|
|
26
|
5
|
|
|
5
|
|
392
|
use YAML qw(Dump); |
|
5
|
|
|
|
|
5649
|
|
|
5
|
|
|
|
|
4187
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub produce { |
29
|
6
|
|
|
6
|
0
|
83
|
my $translator = shift; |
30
|
6
|
|
|
|
|
128
|
my $schema = $translator->schema; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
return Dump({ |
33
|
|
|
|
|
|
|
schema => { |
34
|
|
|
|
|
|
|
tables => { |
35
|
15
|
|
|
|
|
252
|
map { ($_->name => view_table($_)) } |
36
|
|
|
|
|
|
|
$schema->get_tables, |
37
|
|
|
|
|
|
|
}, |
38
|
|
|
|
|
|
|
views => { |
39
|
3
|
|
|
|
|
15
|
map { ($_->name => view_view($_)) } |
40
|
|
|
|
|
|
|
$schema->get_views, |
41
|
|
|
|
|
|
|
}, |
42
|
|
|
|
|
|
|
triggers => { |
43
|
7
|
|
|
|
|
24
|
map { ($_->name => view_trigger($_)) } |
44
|
|
|
|
|
|
|
$schema->get_triggers, |
45
|
|
|
|
|
|
|
}, |
46
|
|
|
|
|
|
|
procedures => { |
47
|
2
|
|
|
|
|
10
|
map { ($_->name => view_procedure($_)) } |
48
|
|
|
|
|
|
|
$schema->get_procedures, |
49
|
|
|
|
|
|
|
}, |
50
|
|
|
|
|
|
|
}, |
51
|
|
|
|
|
|
|
translator => { |
52
|
|
|
|
|
|
|
add_drop_table => $translator->add_drop_table, |
53
|
|
|
|
|
|
|
filename => $translator->filename, |
54
|
|
|
|
|
|
|
no_comments => $translator->no_comments, |
55
|
|
|
|
|
|
|
parser_args => $translator->parser_args, |
56
|
|
|
|
|
|
|
producer_args => $translator->producer_args, |
57
|
|
|
|
|
|
|
parser_type => $translator->parser_type, |
58
|
|
|
|
|
|
|
producer_type => $translator->producer_type, |
59
|
|
|
|
|
|
|
show_warnings => $translator->show_warnings, |
60
|
|
|
|
|
|
|
trace => $translator->trace, |
61
|
|
|
|
|
|
|
version => $translator->version, |
62
|
|
|
|
|
|
|
}, |
63
|
6
|
50
|
|
|
|
153
|
keys %{$schema->extra} ? ('extra' => { $schema->extra } ) : (), |
|
6
|
|
|
|
|
107
|
|
64
|
|
|
|
|
|
|
}); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub view_table { |
68
|
15
|
|
|
15
|
0
|
312
|
my $table = shift; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
return { |
71
|
|
|
|
|
|
|
'name' => $table->name, |
72
|
|
|
|
|
|
|
'order' => $table->order, |
73
|
|
|
|
|
|
|
'options' => $table->options || [], |
74
|
|
|
|
|
|
|
$table->comments ? ('comments' => [ $table->comments ] ) : (), |
75
|
|
|
|
|
|
|
'constraints' => [ |
76
|
16
|
|
|
|
|
92
|
map { view_constraint($_) } $table->get_constraints |
77
|
|
|
|
|
|
|
], |
78
|
|
|
|
|
|
|
'indices' => [ |
79
|
4
|
|
|
|
|
37
|
map { view_index($_) } $table->get_indices |
80
|
|
|
|
|
|
|
], |
81
|
|
|
|
|
|
|
'fields' => { |
82
|
43
|
|
|
|
|
692
|
map { ($_->name => view_field($_)) } |
83
|
|
|
|
|
|
|
$table->get_fields |
84
|
|
|
|
|
|
|
}, |
85
|
15
|
50
|
50
|
|
|
240
|
keys %{$table->extra} ? ('extra' => { $table->extra } ) : (), |
|
15
|
100
|
|
|
|
253
|
|
86
|
|
|
|
|
|
|
}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub view_constraint { |
90
|
16
|
|
|
16
|
0
|
25
|
my $constraint = shift; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
return { |
93
|
|
|
|
|
|
|
'deferrable' => scalar $constraint->deferrable, |
94
|
|
|
|
|
|
|
'expression' => scalar $constraint->expression, |
95
|
16
|
100
|
|
|
|
254
|
'fields' => [ map { ref $_ ? $_->name : $_ } $constraint->field_names ], |
96
|
|
|
|
|
|
|
'match_type' => scalar $constraint->match_type, |
97
|
|
|
|
|
|
|
'name' => scalar $constraint->name, |
98
|
|
|
|
|
|
|
'options' => scalar $constraint->options, |
99
|
|
|
|
|
|
|
'on_delete' => scalar $constraint->on_delete, |
100
|
|
|
|
|
|
|
'on_update' => scalar $constraint->on_update, |
101
|
3
|
50
|
|
|
|
59
|
'reference_fields' => [ map { ref $_ ? $_->name : $_ } $constraint->reference_fields ], |
102
|
|
|
|
|
|
|
'reference_table' => scalar $constraint->reference_table, |
103
|
|
|
|
|
|
|
'type' => scalar $constraint->type, |
104
|
16
|
100
|
|
|
|
232
|
keys %{$constraint->extra} ? ('extra' => { $constraint->extra } ) : (), |
|
16
|
|
|
|
|
472
|
|
105
|
|
|
|
|
|
|
}; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub view_field { |
109
|
43
|
|
|
43
|
0
|
772
|
my $field = shift; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
return { |
112
|
|
|
|
|
|
|
'order' => scalar $field->order, |
113
|
|
|
|
|
|
|
'name' => scalar $field->name, |
114
|
|
|
|
|
|
|
'data_type' => scalar $field->data_type, |
115
|
|
|
|
|
|
|
'size' => [ $field->size ], |
116
|
|
|
|
|
|
|
'default_value' => scalar $field->default_value, |
117
|
|
|
|
|
|
|
'is_nullable' => scalar $field->is_nullable, |
118
|
|
|
|
|
|
|
'is_primary_key' => scalar $field->is_primary_key, |
119
|
|
|
|
|
|
|
'is_unique' => scalar $field->is_unique, |
120
|
|
|
|
|
|
|
$field->is_auto_increment ? ('is_auto_increment' => 1) : (), |
121
|
|
|
|
|
|
|
$field->comments ? ('comments' => [ $field->comments ]) : (), |
122
|
43
|
100
|
|
|
|
688
|
keys %{$field->extra} ? ('extra' => { $field->extra } ) : (), |
|
43
|
100
|
|
|
|
901
|
|
|
|
100
|
|
|
|
|
|
123
|
|
|
|
|
|
|
}; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub view_procedure { |
127
|
2
|
|
|
2
|
0
|
5
|
my $procedure = shift; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
return { |
130
|
|
|
|
|
|
|
'order' => scalar $procedure->order, |
131
|
|
|
|
|
|
|
'name' => scalar $procedure->name, |
132
|
|
|
|
|
|
|
'sql' => scalar $procedure->sql, |
133
|
|
|
|
|
|
|
'parameters' => scalar $procedure->parameters, |
134
|
|
|
|
|
|
|
'owner' => scalar $procedure->owner, |
135
|
|
|
|
|
|
|
'comments' => scalar $procedure->comments, |
136
|
2
|
50
|
|
|
|
43
|
keys %{$procedure->extra} ? ('extra' => { $procedure->extra } ) : (), |
|
2
|
|
|
|
|
44
|
|
137
|
|
|
|
|
|
|
}; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub view_trigger { |
141
|
7
|
|
|
7
|
0
|
13
|
my $trigger = shift; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
return { |
144
|
|
|
|
|
|
|
'order' => scalar $trigger->order, |
145
|
|
|
|
|
|
|
'name' => scalar $trigger->name, |
146
|
|
|
|
|
|
|
'perform_action_when' => scalar $trigger->perform_action_when, |
147
|
|
|
|
|
|
|
'database_events' => scalar $trigger->database_events, |
148
|
|
|
|
|
|
|
'fields' => scalar $trigger->fields, |
149
|
|
|
|
|
|
|
'on_table' => scalar $trigger->on_table, |
150
|
|
|
|
|
|
|
'action' => scalar $trigger->action, |
151
|
|
|
|
|
|
|
(defined $trigger->scope ? ( |
152
|
|
|
|
|
|
|
'scope' => scalar $trigger->scope, |
153
|
|
|
|
|
|
|
) : ()), |
154
|
7
|
100
|
|
|
|
110
|
keys %{$trigger->extra} ? ('extra' => { $trigger->extra } ) : (), |
|
7
|
100
|
|
|
|
212
|
|
155
|
|
|
|
|
|
|
}; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub view_view { |
159
|
3
|
|
|
3
|
0
|
6
|
my $view = shift; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
return { |
162
|
|
|
|
|
|
|
'order' => scalar $view->order, |
163
|
|
|
|
|
|
|
'name' => scalar $view->name, |
164
|
|
|
|
|
|
|
'sql' => scalar $view->sql, |
165
|
|
|
|
|
|
|
'fields' => scalar $view->fields, |
166
|
3
|
100
|
|
|
|
59
|
keys %{$view->extra} ? ('extra' => { $view->extra } ) : (), |
|
3
|
|
|
|
|
52
|
|
167
|
|
|
|
|
|
|
}; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub view_index { |
171
|
4
|
|
|
4
|
0
|
9
|
my $index = shift; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
return { |
174
|
|
|
|
|
|
|
'name' => scalar $index->name, |
175
|
|
|
|
|
|
|
'type' => scalar $index->type, |
176
|
4
|
50
|
|
|
|
77
|
'fields' => [ map { ref($_) ? $_->name : $_ } $index->fields ], |
177
|
|
|
|
|
|
|
'options' => scalar $index->options, |
178
|
4
|
100
|
|
|
|
81
|
keys %{$index->extra} ? ('extra' => { $index->extra } ) : (), |
|
4
|
|
|
|
|
61
|
|
179
|
|
|
|
|
|
|
}; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
1; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 SEE ALSO |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
SQL::Translator, YAML, http://www.yaml.org/. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 AUTHORS |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
darren chamberlain Edarren@cpan.orgE, |
191
|
|
|
|
|
|
|
Ken Youens-Clark Ekclark@cpan.orgE. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |