Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 22598252

Von Moritz Bunkus vor etwa 18 Jahren hinzugefügt

  • ID 2259825299133759a5ba0febf2d88bda8539de7a
  • Vorgänger db53fb4b
  • Nachfolger 5ee0531b

Datenbankupgrades: Es gibt einige Probleme, wenn die CRM installiert ist, weil dann einige Spalten, die in den SQL-Scripten angelegt werden sollten, bereits existieren. Dieses wird nun ueber Perl-Upgradescripte abgefangen.

Unterschiede anzeigen:

sql/Pg-upgrade/Pg-upgrade-2.2.0.19-2.2.0.20.pl
1
#!/usr/bin/perl
2

  
3
die("This script cannot be run from the command line.") unless ($main::form);
4

  
5
sub mydberror {
6
  my ($msg) = @_;
7
  die($dbup_locale->text("Database update error:") .
8
      "<br>$msg<br>" . $DBI::errstr);
9
}
10

  
11
sub mydoquery {
12
  my ($query, $allow_fail) = @_;
13

  
14
  if (!$dbh->do($query)) {
15
    mydberror($query) unless ($allow_fail);
16
    $dbh->rollback();
17
    $dbh->begin_work();
18
  }
19
}
20

  
21
sub update_contacts_add_columns {
22
  # The following columns might already be present due to an
23
  # existing CRM installation:
24
  mydoquery("ALTER TABLE contacts ADD COLUMN cp_fax text", 1);
25

  
26
  # The following columns should not exist:
27
  mydoquery("ALTER TABLE contacts ADD COLUMN cp_mobile1 text");
28
  mydoquery("ALTER TABLE contacts ADD COLUMN cp_mobile2 text");
29
  mydoquery("ALTER TABLE contacts ADD COLUMN cp_satphone text");
30
  mydoquery("ALTER TABLE contacts ADD COLUMN cp_satfax text");
31
  mydoquery("ALTER TABLE contacts ADD COLUMN cp_project text");
32
  mydoquery("ALTER TABLE contacts ADD COLUMN cp_privatphone text");
33
  mydoquery("ALTER TABLE contacts ADD COLUMN cp_privatemail text");
34
  mydoquery("ALTER TABLE contacts ADD COLUMN cp_birthday text");
35

  
36
  return 1;
37
}
38

  
39
return update_contacts_add_columns();
sql/Pg-upgrade/Pg-upgrade-2.2.0.19-2.2.0.20.sql
1
alter table contacts add column cp_fax text;
2
alter table contacts add column cp_mobile1 text;
3
alter table contacts add column cp_mobile2 text;
4
alter table contacts add column cp_satphone text;
5
alter table contacts add column cp_satfax text;
6
alter table contacts add column cp_project text;
7
alter table contacts add column cp_privatphone text;
8
alter table contacts add column cp_privatemail text;
9
alter table contacts add column cp_birthday text;
sql/Pg-upgrade/Pg-upgrade-2.2.0.20-2.2.0.21.pl
1
#!/usr/bin/perl
2

  
3
die("This script cannot be run from the command line.") unless ($main::form);
4

  
5
sub mydberror {
6
  my ($msg) = @_;
7
  die($dbup_locale->text("Database update error:") .
8
      "<br>$msg<br>" . $DBI::errstr);
9
}
10

  
11
sub mydoquery {
12
  my ($query, $allow_fail) = @_;
13

  
14
  if (!$dbh->do($query)) {
15
    mydberror($query) unless ($allow_fail);
16
    $dbh->rollback();
17
    $dbh->begin_work();
18
  }
19
}
20

  
21
sub update_contacts_handle_department {
22
  $dbh->selectrow_array("SELECT cp_abteilung FROM contacts LIMIT 1");
23
  if ($dbh->err) {
24
    $dbh->rollback();
25
    $dbh->begin_work();
26
    mydoquery("ALTER TABLE contacts ADD COLUMN cp_abteilung text");
27
    mydoquery("UPDATE contacts SET cp_abteilung = cp_department");
28
  }
29

  
30
  mydoquery("ALTER TABLE contacts DROP COLUMN cp_department", 1);
31

  
32
  return 1;
33
}
34

  
35
return update_contacts_handle_department();
sql/Pg-upgrade/Pg-upgrade-2.2.0.20-2.2.0.21.sql
1
alter table contacts add column cp_abteilung text;
2
update contacts set cp_abteilung=cp_department;
3
alter table contacts drop column cp_department;

Auch abrufbar als: Unified diff