Revision 7e96894a
Von Moritz Bunkus vor fast 17 Jahren hinzugefügt
scripts/dbupgrade2_tool.pl | ||
---|---|---|
32 | 32 |
####### |
33 | 33 |
|
34 | 34 |
my ($opt_list, $opt_tree, $opt_rtree, $opt_nodeps, $opt_graphviz, $opt_help); |
35 |
my ($opt_user, $opt_apply); |
|
35 |
my ($opt_user, $opt_apply, $opt_applied);
|
|
36 | 36 |
|
37 | 37 |
our (%myconfig, $form, $user, $auth); |
38 | 38 |
|
... | ... | |
61 | 61 |
--apply=tag Applies the database upgrades 'tag' and all |
62 | 62 |
upgrades it depends on. If '--apply' is used |
63 | 63 |
then the option '--user' must be used as well. |
64 |
--applied List the applied database upgrades for the |
|
65 |
database that the user given with '--user' uses. |
|
64 | 66 |
--help Show this help and exit. |
65 | 67 |
|
66 | 68 |
Options: |
... | ... | |
258 | 260 |
$dbh->disconnect(); |
259 | 261 |
} |
260 | 262 |
|
263 |
sub dump_sql_result { |
|
264 |
my ($results, $column_order) = @_; |
|
265 |
|
|
266 |
my %column_lengths = map { $_, length $_ } keys %{ $results->[0] }; |
|
267 |
|
|
268 |
foreach my $row (@{ $results }) { |
|
269 |
map { $column_lengths{$_} = length $row->{$_} if (length $row->{$_} > $column_lengths{$_}) } keys %{ $row }; |
|
270 |
} |
|
271 |
|
|
272 |
my @sorted_names; |
|
273 |
if ($column_order && scalar @{ $column_order }) { |
|
274 |
@sorted_names = @{ $column_order }; |
|
275 |
} else { |
|
276 |
@sorted_names = sort keys %column_lengths; |
|
277 |
} |
|
278 |
|
|
279 |
my $format = join('|', map { '%-' . $column_lengths{$_} . 's' } @sorted_names) . "\n"; |
|
280 |
|
|
281 |
printf $format, @sorted_names; |
|
282 |
print join('+', map { '-' x $column_lengths{$_} } @sorted_names) . "\n"; |
|
283 |
|
|
284 |
foreach my $row (@{ $results }) { |
|
285 |
printf $format, map { $row->{$_} } @sorted_names; |
|
286 |
} |
|
287 |
printf "(\%d row\%s)\n", scalar @{ $results }, scalar @{ $results } > 1 ? 's' : ''; |
|
288 |
} |
|
289 |
|
|
290 |
sub dump_applied { |
|
291 |
my @results; |
|
292 |
|
|
293 |
my $dbh = $form->dbconnect_noauto(\%myconfig); |
|
294 |
|
|
295 |
$dbh->{PrintWarn} = 0; |
|
296 |
$dbh->{PrintError} = 0; |
|
297 |
|
|
298 |
$user->create_schema_info_table($form, $dbh); |
|
299 |
|
|
300 |
my $query = qq|SELECT tag, login, itime FROM schema_info ORDER BY itime|; |
|
301 |
$sth = $dbh->prepare($query); |
|
302 |
$sth->execute() || $form->dberror($query); |
|
303 |
while (my $ref = $sth->fetchrow_hashref()) { |
|
304 |
push @results, $ref; |
|
305 |
} |
|
306 |
$sth->finish(); |
|
307 |
|
|
308 |
$dbh->disconnect(); |
|
309 |
|
|
310 |
if (!scalar @results) { |
|
311 |
print "No database upgrades have been applied yet.\n"; |
|
312 |
} else { |
|
313 |
dump_sql_result(\@results, [qw(tag login itime)]); |
|
314 |
} |
|
315 |
} |
|
316 |
|
|
261 | 317 |
sub build_upgrade_order { |
262 | 318 |
my $name = shift; |
263 | 319 |
my $order = shift; |
... | ... | |
296 | 352 |
"graphviz:s" => \$opt_graphviz, |
297 | 353 |
"user=s" => \$opt_user, |
298 | 354 |
"apply=s" => \$opt_apply, |
355 |
"applied" => \$opt_applied, |
|
299 | 356 |
"help" => \$opt_help, |
300 | 357 |
); |
301 | 358 |
|
... | ... | |
330 | 387 |
} |
331 | 388 |
|
332 | 389 |
if ($opt_apply) { |
333 |
$form->error("--apply used but no configuration file given with --user.") if (!$user);
|
|
390 |
$form->error("--apply used but no user name given with --user.") if (!$user);
|
|
334 | 391 |
apply_upgrade($opt_apply); |
335 | 392 |
} |
393 |
|
|
394 |
if ($opt_applied) { |
|
395 |
$form->error("--applied used but no user name given with --user.") if (!$user); |
|
396 |
dump_applied(); |
|
397 |
} |
Auch abrufbar als: Unified diff
Eine Option zur Ausgabe bereits angewandter Datenbankupgrades hinzugefügt.