Revision b7bb9320
Von Moritz Bunkus vor mehr als 16 Jahren hinzugefügt
sql/Pg-upgrade2/warehouse.pl | ||
---|---|---|
4 | 4 |
|
5 | 5 |
|
6 | 6 |
die("This script cannot be run from the command line.") unless ($main::form); |
7 |
|
|
8 |
sub mydberror { |
|
9 |
my ($msg) = @_; |
|
10 |
die($dbup_locale->text("Database update error:") . |
|
11 |
"<br>$msg<br>" . $DBI::errstr); |
|
12 |
} |
|
13 |
|
|
14 |
sub do_query { |
|
15 |
my ($query, $may_fail) = @_; |
|
16 |
|
|
17 |
if (!$dbh->do($query)) { |
|
18 |
mydberror($query) unless ($may_fail); |
|
19 |
$dbh->rollback(); |
|
20 |
$dbh->begin_work(); |
|
21 |
} |
|
22 |
} |
|
23 |
|
|
7 | 24 |
$do_sql_migration = 0; |
8 | 25 |
|
9 | 26 |
sub print_question { |
... | ... | |
32 | 49 |
|
33 | 50 |
my $migration_code = <<EOF |
34 | 51 |
|
35 |
-- Warehouse anpassen
|
|
52 |
-- Adjust warehouse
|
|
36 | 53 |
INSERT INTO warehouse (description) VALUES ('$warehouse'); |
37 | 54 |
|
38 | 55 |
UPDATE tmp_parts SET bin = NULL WHERE bin = ''; |
39 | 56 |
|
40 |
-- Warenbestand wiederherstellen
|
|
57 |
-- Restore old onhand
|
|
41 | 58 |
INSERT INTO bin |
42 | 59 |
(warehouse_id, description) |
43 | 60 |
(SELECT DISTINCT warehouse.id, COALESCE(bin, '$bin') |
... | ... | |
57 | 74 |
my $query = $sqlcode; |
58 | 75 |
$query .= $migration_code if $do_sql_migration; |
59 | 76 |
|
60 |
do_query($main::form, $dbh, $query);
|
|
77 |
do_query($query); |
|
61 | 78 |
|
62 | 79 |
return 1; |
63 | 80 |
} |
... | ... | |
65 | 82 |
|
66 | 83 |
|
67 | 84 |
$sqlcode = <<EOF |
68 |
-- Tabelle "bin" f?r Lagerpl?tze.
|
|
85 |
-- Table "bin" for bins.
|
|
69 | 86 |
CREATE TABLE bin ( |
70 | 87 |
id integer NOT NULL DEFAULT nextval('id'), |
71 | 88 |
warehouse_id integer NOT NULL, |
... | ... | |
80 | 97 |
CREATE TRIGGER mtime_bin BEFORE UPDATE ON bin |
81 | 98 |
FOR EACH ROW EXECUTE PROCEDURE set_mtime(); |
82 | 99 |
|
83 |
-- Tabelle "warehouse"
|
|
100 |
-- Table "warehouse" |
|
84 | 101 |
ALTER TABLE warehouse ADD COLUMN sortkey integer; |
85 | 102 |
CREATE SEQUENCE tmp_counter; |
86 | 103 |
UPDATE warehouse SET sortkey = nextval('tmp_counter'); |
... | ... | |
92 | 109 |
CREATE TRIGGER mtime_warehouse BEFORE UPDATE ON warehouse |
93 | 110 |
FOR EACH ROW EXECUTE PROCEDURE set_mtime(); |
94 | 111 |
|
95 |
-- Tabelle "transfer_type"
|
|
112 |
-- Table "transfer_type" |
|
96 | 113 |
CREATE TABLE transfer_type ( |
97 | 114 |
id integer NOT NULL DEFAULT nextval('id'), |
98 | 115 |
direction varchar(10) NOT NULL, |
... | ... | |
118 | 135 |
INSERT INTO transfer_type (direction, description, sortkey) VALUES ('transfer', 'transfer', 10); |
119 | 136 |
INSERT INTO transfer_type (direction, description, sortkey) VALUES ('transfer', 'correction', 11); |
120 | 137 |
|
121 |
-- Anpassungen an "inventory".
|
|
138 |
-- Modifications to "inventory".
|
|
122 | 139 |
DELETE FROM inventory; |
123 | 140 |
|
124 | 141 |
ALTER TABLE inventory ADD COLUMN bin_id integer; |
... | ... | |
150 | 167 |
ALTER TABLE inventory ADD COLUMN chargenumber text; |
151 | 168 |
ALTER TABLE inventory ADD COLUMN comment text; |
152 | 169 |
|
153 |
-- "onhand" in "parts" ?ber einen Trigger automatisch berechnen lassen. |
|
154 |
-- Vorher Warenbestand sichern JZ |
|
170 |
-- Let "onhand" in "parts" be calculated automatically by a trigger. |
|
155 | 171 |
SELECT id, onhand, bin INTO TEMP TABLE tmp_parts FROM parts WHERE onhand > 0; |
156 | 172 |
ALTER TABLE parts DROP COLUMN onhand; |
157 | 173 |
ALTER TABLE parts ADD COLUMN onhand numeric(25,5); |
Auch abrufbar als: Unified diff
Zwei Probleme, die behoben werden:
1. Bei UTF-8-Installationen dürfen keine ISO-8859-1-codierte Umlaute enthalten sein.
2. Die Funktion "do_query()" wird von vielen Upgradescripten neu definiert und hat dann eine andere Signatur als die "DBUtils::do_query()". Das führte dazu, dass warehouse.pl nur dann funktionierte, wenn nicht gleichzeitig eines derjenigen Upgradescripte ausgeführt wurde, das do_query() neu definiert. Fix ist, do_query() in warehouse.pl wie in den anderen Perl-Datenbankupgradescripten zu definieren und zu verwenden.