Revision a96f9e80
Von Moritz Bunkus vor fast 17 Jahren hinzugefügt
scripts/dbupgrade2_tool.pl | ||
---|---|---|
79 | 79 |
} |
80 | 80 |
|
81 | 81 |
sub calc_rev_depends { |
82 |
map({ $_->{"rev_depends"} = []; } values(%{$controls}));
|
|
83 |
foreach my $control (values(%{$controls})) { |
|
84 |
map({ push(@{$controls->{$_}{"rev_depends"}}, $control->{"tag"}) }
|
|
85 |
@{$control->{"depends"}});
|
|
82 |
map { $_->{rev_depends} = []; } values %{ $controls };
|
|
83 |
|
|
84 |
foreach my $control (values %{ $controls }) {
|
|
85 |
map { push @{ $controls->{$_}->{rev_depends} }, $control->{tag} } @{ $control->{depends} };
|
|
86 | 86 |
} |
87 | 87 |
} |
88 | 88 |
|
89 | 89 |
sub dump_list { |
90 | 90 |
my @sorted_controls = sort_dbupdate_controls($controls); |
91 | 91 |
|
92 |
print("LIST VIEW\n\n"); |
|
93 |
print("number tag depth priority\n"); |
|
92 |
print "LIST VIEW\n\n" . |
|
93 |
"number tag depth priority\n"; |
|
94 |
|
|
94 | 95 |
$i = 0; |
95 | 96 |
foreach (@sorted_controls) { |
96 |
print("$i $_->{tag} $_->{depth} $_->{priority}\n");
|
|
97 |
print "$i $_->{tag} $_->{depth} $_->{priority}\n";
|
|
97 | 98 |
$i++; |
98 | 99 |
} |
99 | 100 |
|
100 |
print("\n");
|
|
101 |
print "\n";
|
|
101 | 102 |
} |
102 | 103 |
|
103 | 104 |
sub dump_node { |
104 | 105 |
my ($tag, $depth) = @_; |
105 | 106 |
|
106 |
print(" " x $depth . $tag . "\n");
|
|
107 |
print " " x $depth . $tag . "\n";
|
|
107 | 108 |
|
108 |
my $c = $controls->{$tag}; |
|
109 |
my $num = scalar(@{$c->{"depends"}}); |
|
110 |
for (my $i = 0; $i < $num; $i++) { |
|
111 |
dump_node($c->{"depends"}[$i], $depth + 1); |
|
109 |
foreach my $dep_tag (@{ $controls->{$tag}->{depends} }) { |
|
110 |
dump_node($dep_tag, $depth + 1); |
|
112 | 111 |
} |
113 | 112 |
} |
114 | 113 |
|
115 | 114 |
sub dump_tree { |
116 |
print("TREE VIEW\n\n");
|
|
115 |
print "TREE VIEW\n\n";
|
|
117 | 116 |
|
118 | 117 |
calc_rev_depends(); |
119 | 118 |
|
120 | 119 |
my @sorted_controls = sort_dbupdate_controls($controls); |
121 | 120 |
|
122 | 121 |
foreach my $control (@sorted_controls) { |
123 |
dump_node($control->{"tag"}, "") unless (@{$control->{"rev_depends"}});
|
|
122 |
dump_node($control->{tag}, "") unless (@{ $control->{rev_depends} });
|
|
124 | 123 |
} |
125 | 124 |
|
126 |
print("\n");
|
|
125 |
print "\n";
|
|
127 | 126 |
} |
128 | 127 |
|
129 | 128 |
sub dump_node_reverse { |
130 | 129 |
my ($tag, $depth) = @_; |
131 | 130 |
|
132 |
print(" " x $depth . $tag . "\n");
|
|
131 |
print " " x $depth . $tag . "\n";
|
|
133 | 132 |
|
134 |
my $c = $controls->{$tag}; |
|
135 |
my $num = scalar(@{$c->{"rev_depends"}}); |
|
136 |
for (my $i = 0; $i < $num; $i++) { |
|
137 |
dump_node_reverse($c->{"rev_depends"}[$i], $depth + 1); |
|
133 |
foreach my $dep_tag (@{ $controls->{$tag}->{rev_depends} }) { |
|
134 |
dump_node_reverse($dep_tag, $depth + 1); |
|
138 | 135 |
} |
139 | 136 |
} |
140 | 137 |
|
141 | 138 |
sub dump_tree_reverse { |
142 |
print("REVERSE TREE VIEW\n\n");
|
|
139 |
print "REVERSE TREE VIEW\n\n";
|
|
143 | 140 |
|
144 | 141 |
calc_rev_depends(); |
145 | 142 |
|
146 | 143 |
my @sorted_controls = sort_dbupdate_controls($controls); |
147 | 144 |
|
148 | 145 |
foreach my $control (@sorted_controls) { |
149 |
last if ($control->{"depth"} > 1);
|
|
150 |
dump_node_reverse($control->{"tag"}, "");
|
|
146 |
last if ($control->{depth} > 1);
|
|
147 |
dump_node_reverse($control->{tag}, "");
|
|
151 | 148 |
} |
152 | 149 |
|
153 |
print("\n");
|
|
150 |
print "\n";
|
|
154 | 151 |
} |
155 | 152 |
|
156 | 153 |
sub dump_graphviz { |
157 | 154 |
my $file_name = shift || "db_dependencies.ps"; |
158 | 155 |
|
159 |
print("GRAPHVIZ POSTCRIPT\n\n");
|
|
160 |
print("Output will be written to '${file_name}'\n");
|
|
156 |
print "GRAPHVIZ POSTCRIPT\n\n";
|
|
157 |
print "Output will be written to '${file_name}'\n";
|
|
161 | 158 |
|
162 | 159 |
calc_rev_depends(); |
163 | 160 |
|
164 | 161 |
$dot = "|dot -Tps "; |
165 | 162 |
open OUT, "${dot}> \"${file_name}\"" || die; |
166 | 163 |
|
167 |
print(OUT |
|
168 |
"digraph db_dependencies {\n" . |
|
169 |
"node [shape=box style=filled fillcolor=white];\n"); |
|
164 |
print OUT |
|
165 |
"digraph db_dependencies {\n" . |
|
166 |
"node [shape=box style=filled fillcolor=white];\n"; |
|
167 |
|
|
170 | 168 |
my %ranks; |
171 |
foreach my $c (values(%{$controls})) {
|
|
172 |
$ranks{$c->{"depth"}} ||= [];
|
|
169 |
foreach my $c (values %{ $controls }) {
|
|
170 |
$ranks{$c->{depth}} ||= [];
|
|
173 | 171 |
|
174 |
my ($pre, $post) = ('node [fillcolor=lightgray] ', 'node [fillcolor=white] ') if !@{ $c->{"rev_depends"} };
|
|
172 |
my ($pre, $post) = ('node [fillcolor=lightgray] ', 'node [fillcolor=white] ') if (!scalar @{ $c->{rev_depends} });
|
|
175 | 173 |
|
176 | 174 |
push @{ $ranks{$c->{"depth"}} }, qq|${pre}"$c->{tag}"; ${post}|; |
177 | 175 |
} |
178 |
foreach (sort(keys(%ranks))) { |
|
176 |
|
|
177 |
foreach (sort keys %ranks) { |
|
179 | 178 |
print OUT "{ rank = same; ", join("", @{ $ranks{$_} }), " }\n"; |
180 | 179 |
} |
181 |
foreach my $c (values(%{$controls})) { |
|
182 |
print(OUT "$c->{tag};\n"); |
|
183 |
foreach my $d (@{$c->{"depends"}}) { |
|
184 |
print(OUT "$c->{tag} -> $d;\n"); |
|
180 |
|
|
181 |
foreach my $c (values %{ $controls }) { |
|
182 |
print OUT "$c->{tag};\n"; |
|
183 |
|
|
184 |
foreach my $d (@{ $c->{depends} }) { |
|
185 |
print OUT "$c->{tag} -> $d;\n"; |
|
185 | 186 |
} |
186 | 187 |
} |
187 |
print(OUT "}\n"); |
|
188 |
close(OUT); |
|
188 |
|
|
189 |
print OUT "}\n"; |
|
190 |
close OUT; |
|
189 | 191 |
} |
190 | 192 |
|
191 | 193 |
sub dump_nodeps { |
192 | 194 |
calc_rev_depends(); |
193 | 195 |
|
194 |
print("SCRIPTS NO OTHER SCRIPTS DEPEND ON\n\n" . |
|
195 |
join("\n", |
|
196 |
map({ $_->{"tag"} } |
|
197 |
grep({ !@{$_->{"rev_depends"}} } |
|
198 |
values(%{$controls})))) . |
|
199 |
"\n\n"); |
|
196 |
print "SCRIPTS NO OTHER SCRIPTS DEPEND ON\n\n" . |
|
197 |
join("\n", map { $_->{tag} } grep { !scalar @{ $_->{rev_depends} } } values %{ $controls }) . |
|
198 |
"\n\n"; |
|
200 | 199 |
} |
201 | 200 |
|
202 | 201 |
sub apply_upgrade { |
... | ... | |
206 | 205 |
|
207 | 206 |
if ($name eq "ALL") { |
208 | 207 |
calc_rev_depends(); |
209 |
@all_tags = map { $_->{"tag"} } grep { !@{$_->{"rev_depends"}} } values %{$controls};
|
|
208 |
@all_tags = map { $_->{tag} } grep { !@{$_->{rev_depends}} } values %{ $controls };
|
|
210 | 209 |
|
211 | 210 |
} else { |
212 | 211 |
$form->error("Unknown dbupgrade tag '$name'") if (!$controls->{$name}); |
... | ... | |
217 | 216 |
build_upgrade_order($tag, \@order, \%tags); |
218 | 217 |
} |
219 | 218 |
|
220 |
my @upgradescripts = map { $controls->{$_}->{"applied"} = 0; $controls->{$_} } @order;
|
|
219 |
my @upgradescripts = map { $controls->{$_}->{applied} = 0; $controls->{$_} } @order;
|
|
221 | 220 |
|
222 | 221 |
my $dbh = $form->dbconnect_noauto(\%myconfig); |
223 | 222 |
|
... | ... | |
230 | 229 |
$sth = $dbh->prepare($query); |
231 | 230 |
$sth->execute() || $form->dberror($query); |
232 | 231 |
while (($tag) = $sth->fetchrow_array()) { |
233 |
$controls->{$tag}->{"applied"} = 1 if defined $controls->{$tag};
|
|
232 |
$controls->{$tag}->{applied} = 1 if defined $controls->{$tag};
|
|
234 | 233 |
} |
235 | 234 |
$sth->finish(); |
236 | 235 |
|
237 |
@upgradescripts = sort { $a->{"priority"} <=> $b->{"priority"} } grep { !$_->{"applied"} } @upgradescripts;
|
|
236 |
@upgradescripts = sort { $a->{priority} <=> $b->{priority} } grep { !$_->{applied} } @upgradescripts;
|
|
238 | 237 |
if (!@upgradescripts) { |
239 | 238 |
print "The upgrade has already been applied.\n"; |
240 | 239 |
exit 0; |
241 | 240 |
} |
242 | 241 |
|
243 | 242 |
foreach my $control (@upgradescripts) { |
244 |
$control->{"file"} =~ /\.(sql|pl)$/;
|
|
243 |
$control->{file} =~ /\.(sql|pl)$/;
|
|
245 | 244 |
my $file_type = $1; |
246 | 245 |
|
247 | 246 |
# apply upgrade |
... | ... | |
264 | 263 |
|
265 | 264 |
my $control = $controls->{$name}; |
266 | 265 |
|
267 |
foreach my $dependency (@{ $control->{"depends"} }) {
|
|
266 |
foreach my $dependency (@{ $control->{depends} }) {
|
|
268 | 267 |
next if $tags->{$dependency}; |
269 | 268 |
$tags->{$dependency} = 1; |
270 | 269 |
build_upgrade_order($dependency, $order, $tag); |
... | ... | |
278 | 277 |
####### |
279 | 278 |
####### |
280 | 279 |
|
281 |
eval { require "lx-erp.conf"; }; |
|
280 |
eval { require "config/lx-erp.conf"; }; |
|
281 |
eval { require "config/lx-erp-local.conf"; } if (-f "config/lx-erp-local.conf"); |
|
282 | 282 |
|
283 | 283 |
$form = Form->new(); |
284 | 284 |
$locale = Locale->new("de", "login"); |
... | ... | |
287 | 287 |
####### |
288 | 288 |
####### |
289 | 289 |
|
290 |
GetOptions("list" => \$opt_list, |
|
291 |
"tree" => \$opt_tree, |
|
292 |
"rtree" => \$opt_rtree, |
|
293 |
"nodeps" => \$opt_nodeps, |
|
290 |
GetOptions("list" => \$opt_list,
|
|
291 |
"tree" => \$opt_tree,
|
|
292 |
"rtree" => \$opt_rtree,
|
|
293 |
"nodeps" => \$opt_nodeps,
|
|
294 | 294 |
"graphviz:s" => \$opt_graphviz, |
295 |
"user=s" => \$opt_user, |
|
296 |
"apply=s" => \$opt_apply, |
|
297 |
"help" => \$opt_help, |
|
295 |
"user=s" => \$opt_user,
|
|
296 |
"apply=s" => \$opt_apply,
|
|
297 |
"help" => \$opt_help,
|
|
298 | 298 |
); |
299 | 299 |
|
300 |
if ($opt_help) { |
|
301 |
show_help(); |
|
302 |
} |
|
300 |
show_help() if ($opt_help); |
|
303 | 301 |
|
304 | 302 |
$controls = parse_dbupdate_controls($form, "Pg"); |
305 | 303 |
|
306 |
if ($opt_list) { |
|
307 |
dump_list(); |
|
308 |
} |
|
309 |
|
|
310 |
if ($opt_tree) { |
|
311 |
dump_tree(); |
|
312 |
} |
|
313 |
|
|
314 |
if ($opt_rtree) { |
|
315 |
dump_tree_reverse(); |
|
316 |
} |
|
317 |
|
|
318 |
if (defined $opt_graphviz) { |
|
319 |
dump_graphviz($opt_graphviz); |
|
320 |
} |
|
321 |
|
|
322 |
if ($opt_nodeps) { |
|
323 |
dump_nodeps(); |
|
324 |
} |
|
304 |
dump_list() if ($opt_list); |
|
305 |
dump_tree() if ($opt_tree); |
|
306 |
dump_tree_reverse() if ($opt_rtree); |
|
307 |
dump_graphviz($opt_graphviz) if (defined $opt_graphviz); |
|
308 |
dump_nodeps() if ($opt_nodeps); |
|
325 | 309 |
|
326 | 310 |
if ($opt_user) { |
327 | 311 |
my $file_name = "users/${opt_user}.conf"; |
Auch abrufbar als: Unified diff
Kosmetik, und den Speicherort der lx-erp.conf angepasst.