Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 00cfe3f2

Von Sven Schöling vor etwa 12 Jahren hinzugefügt

dbupgrade script kann jetzt auch upgrade scripte erzeugen.

scripts/dbupgrade2_tool.pl --create=<tag> --type=<sql|pl>

speichert die Datei unter dem richtigen Namen, und öffnet sie in $EDITOR

Unterschiede anzeigen:

SL/DBUpgrade2.pm
25 25

  
26 26
  $params{path_suffix} ||= '';
27 27
  $params{schema}      ||= '';
28
  $params{path}          = "sql/" . $params{dbdriver} . "-upgrade2" . $params{path_suffix};
28 29

  
29 30
  map { $self->{$_} = $params{$_} } keys %params;
30 31

  
31 32
  return $self;
32 33
}
33 34

  
35
sub path {
36
  $_[0]{path};
37
}
38

  
34 39
sub parse_dbupdate_controls {
35 40
  $::lxdebug->enter_sub();
36 41

  
......
42 47
  local *IN;
43 48
  my %all_controls;
44 49

  
45
  my $path = "sql/" . $self->{dbdriver} . "-upgrade2" . $self->{path_suffix};
50
  my $path = $self->path;
46 51

  
47 52
  foreach my $file_name (<$path/*.sql>, <$path/*.pl>) {
48 53
    next unless (open(IN, $file_name));
scripts/dbupgrade2_tool.pl
43 43

  
44 44
my ($opt_list, $opt_tree, $opt_rtree, $opt_nodeps, $opt_graphviz, $opt_help);
45 45
my ($opt_user, $opt_apply, $opt_applied, $opt_unapplied, $opt_format, $opt_test_utf8);
46
my ($opt_dbhost, $opt_dbport, $opt_dbname, $opt_dbuser, $opt_dbpassword);
46
my ($opt_dbhost, $opt_dbport, $opt_dbname, $opt_dbuser, $opt_dbpassword, $opt_create, $opt_type);
47
my ($opt_description, $opt_encoding, @opt_depends);
47 48

  
48 49
our (%myconfig, $form, $user, $auth, $locale, $controls, $dbupgrader);
49 50

  
......
231 232
    "\n\n";
232 233
}
233 234

  
235
sub create_upgrade {
236
  my (%params) = @_;
237

  
238
  my $filename    = $params{filename};
239
  my $dbupgrader  = $params{dbupgrader};
240
  my $type        = $params{type}        || '';
241
  my $description = $params{description} || '';
242
  my $encoding    = $params{encoding}    || 'utf-8';
243
  my @depends     = @{ $params{depends} };
244

  
245
  if (!@depends) {
246
    my @releases = grep { /^release_/ } keys %$controls;
247
    @depends = ((sort @releases)[-1]);
248
  }
249

  
250
  my $comment;
251
  if ($type eq 'sql') {
252
    $comment = '--';
253
  } elsif ($type eq 'pl') {
254
    $comment = '#';
255
  } elsif (!$type) {
256
    die 'Error: No --type was given but is required for --create.';
257
  } else {
258
    die 'Error: Unknown --type. Try "sql" or "pl".';
259
  }
260

  
261
  my $full_filename = $dbupgrader->path . '/' . $filename . '.' . $type;
262

  
263
  die "file '$full_filename' already exists, aborting" if -f $full_filename;
264

  
265

  
266
  open my $fh, ">:utf8", $full_filename or die "can't open $full_filename";
267
  print $fh "$comment \@tag: $filename\n";
268
  print $fh "$comment \@description: $description\n";
269
  print $fh "$comment \@depends: @depends\n";
270
  print $fh "$comment \@encoding: $encoding\n";
271
  close $fh;
272

  
273
  system("\$EDITOR $full_filename");
274
  exit 0;
275
}
276

  
234 277
sub apply_upgrade {
235 278
  my $name = shift;
236 279

  
......
399 442
           "user=s"       => \$opt_user,
400 443
           "apply=s"      => \$opt_apply,
401 444
           "applied"      => \$opt_applied,
445
           "create=s"     => \$opt_create,
446
           "type=s"       => \$opt_type,
447
           "encoding=s"   => \$opt_encoding,
448
           "description=s" => \$opt_description,
449
           "depends=s"    => \@opt_depends,
402 450
           "unapplied"    => \$opt_unapplied,
403 451
           "test-utf8"    => \$opt_test_utf8,
404 452
           "dbhost:s"     => \$opt_dbhost,
......
420 468
dump_graphviz('file_name' => $opt_graphviz,
421 469
              'format'    => $opt_format)   if (defined $opt_graphviz);
422 470
dump_nodeps()                               if ($opt_nodeps);
471
create_upgrade(filename   => $opt_create,
472
               dbupgrader  => $dbupgrader,
473
               type        => $opt_type,
474
               description => $opt_description,
475
               encoding    => $opt_encoding,
476
               depends     => \@opt_depends) if ($opt_create);
423 477

  
424 478
if ($opt_user) {
425 479
  $auth = SL::Auth->new();
......
456 510
  dump_unapplied();
457 511
}
458 512

  
513

  
459 514
if ($opt_test_utf8) {
460 515
  $form->error("--test-utf8 used but no database name given with --dbname.") if (!$opt_dbname);
461 516

  

Auch abrufbar als: Unified diff