d6b0ebb0ab8afca591fa850e9e4f98b3f4d10964
[kivitendo-erp.git] / sql / Pg-upgrade-2.1.1-2.1.2.sql
1
2 --Update der Numeric-Spalten von 5 auf 10 Vorkommastellen
3 --
4 --TABLE ap
5 alter table ap rename column paid to paidold;
6 alter table ap add column paid numeric(15,5);
7 update ap set paid=paidold;
8 alter table ap drop column paidold;
9 --
10 alter table ap rename column netamount to netamountold;
11 alter table ap add column netamount numeric(15,5);
12 update ap set netamount=netamountold;
13 alter table ap drop column netamountold;
14 --
15 alter table ap rename column amount to amountold;
16 alter table ap add column amount numeric(15,5);
17 update ap set amount=amountold;
18 alter table ap drop column amountold;
19 --
20 --TABLE acc_trans
21 alter table acc_trans rename column amount to amountold;
22 alter table acc_trans add column amount numeric(15,5);
23 update acc_trans set amount=amountold;
24 alter table acc_trans drop column amountold;
25 --
26 --TABLE ar
27 alter table ar rename column amount to amountold;
28 alter table ar add column amount numeric(15,5);
29 update ar set amount=amountold;
30 alter table ar drop column amountold;
31 --
32 alter table ar rename column netamount to netamountold;
33 alter table ar add column netamount numeric(15,5);
34 update ar set netamount=netamountold;
35 alter table ar drop column netamountold;
36 --
37 alter table ar rename column paid to paidold;
38 alter table ar add column paid numeric(15,5);
39 update ar set paid=paidold;
40 alter table ar drop column paidold;
41 --
42 --TABLE customer
43 alter table customer rename column creditlimit to creditlimitold;
44 alter table customer add column creditlimit numeric(15,5);
45 update customer set creditlimit=creditlimitold;
46 alter table customer drop column creditlimitold;
47 --
48 --TABLE exchangerate
49 alter table exchangerate rename column buy to buyold;
50 alter table exchangerate add column buy numeric(15,5);
51 update exchangerate set buy=buyold;
52 alter table exchangerate drop column buyold;
53 --
54 alter table exchangerate rename column sell to sellold;
55 alter table exchangerate add column sell numeric(15,5);
56 update exchangerate set sell=sellold;
57 alter table exchangerate drop column sellold;
58 --
59 --TABLE invoice
60 alter table invoice rename column sellprice to sellpriceold;
61 alter table invoice add column sellprice numeric(15,5);
62 update invoice set sellprice=sellpriceold;
63 alter table invoice drop column sellpriceold;
64 --
65 alter table invoice rename column fxsellprice to fxsellpriceold;
66 alter table invoice add column fxsellprice numeric(15,5);
67 update invoice set fxsellprice=fxsellpriceold;
68 alter table invoice drop column fxsellpriceold;
69 --
70 --TABLE oe
71 alter table oe rename column amount to amountold;
72 alter table oe add column amount numeric(15,5);
73 update oe set amount=amountold;
74 alter table oe drop column amountold;
75 --
76 alter table oe rename column netamount to netamountold;
77 alter table oe add column netamount numeric(15,5);
78 update oe set netamount=netamountold;
79 alter table oe drop column netamountold;
80 --
81 --TABLE orderitems
82 alter table orderitems rename column sellprice to sellpriceold;
83 alter table orderitems add column sellprice numeric(15,5);
84 update orderitems set sellprice=sellpriceold;
85 alter table orderitems drop column sellpriceold;
86 --
87 --TABLE parts
88 alter table parts rename column listprice to listpriceold;
89 alter table parts add column listprice numeric(15,5);
90 update parts set listprice=listpriceold;
91 alter table parts drop column listpriceold;
92 --
93 alter table parts rename column sellprice to sellpriceold;
94 alter table parts add column sellprice numeric(15,5);
95 update parts set sellprice=sellpriceold;
96 alter table parts drop column sellpriceold;
97 --
98 alter table parts rename column lastcost to lastcostold;
99 alter table parts add column lastcost numeric(15,5);
100 update parts set lastcost=lastcostold;
101 alter table parts drop column lastcostold;
102 --
103 --TABLE tax
104 alter table tax rename column rate to rateold;
105 alter table tax add column rate numeric(15,5);
106 update tax set rate=rateold;
107 alter table tax drop column rateold;
108 --
109 --TABLE vendor
110 alter table vendor rename column creditlimit to creditlimitold;
111 alter table vendor add column creditlimit numeric(15,5);
112 update vendor set creditlimit=creditlimitold;
113 alter table vendor drop column creditlimitold;
114 --
115
116 --New Fields for customer and vendor
117 alter table vendor add column obsolete boolean;
118 alter table vendor alter column obsolete set default 'false';
119 alter table customer add column obsolete boolean;
120 alter table customer alter column obsolete set default 'false';
121 alter table customer add column ustid varchar(12);
122 alter table vendor add column ustid varchar(12);
123
124 alter table customer add column username varchar(50);
125 alter table vendor add column username varchar(50);
126 alter table customer add column user_password varchar(12);
127 alter table vendor add column user_password varchar(12);
128 alter table customer add column salesman_id integer;
129 alter table vendor add column salesman_id integer;
130
131 -- Addon for business
132 alter table business add column salesman boolean;
133 alter table business alter column salesman set default 'false';
134 alter table business add column customernumberinit text;
135
136 alter table parts add column ve integer;
137 alter table parts add column gv numeric(15,5);
138 --
139
140 -- Add table contrains
141 alter table customer alter name SET NOT NULL;
142 alter table vendor alter name set NOT NULL;
143 alter table chart alter accno set NOT NULL;
144 alter table parts alter partnumber set NOT NULL;
145 alter table ar alter invnumber set NOT NULL;
146 alter table ap alter invnumber set NOT NULL;
147 alter table oe alter ordnumber set NOT NULL;
148
149 alter table gl add primary key (id);
150 alter table chart add primary key (id);
151 alter table parts add primary key (id);
152 alter table invoice add primary key (id);
153 alter table vendor add primary key (id);
154 alter table customer add primary key (id);
155 alter table contacts add primary key (cp_id);
156 alter table ar add primary key (id);
157 alter table ap add primary key (id);
158 alter table oe add primary key (id);
159 alter table employee add primary key (id);
160 alter table warehouse add primary key (id);
161 alter table business add primary key (id);
162 alter table license add primary key (id);
163 alter table orderitems add primary key (id);
164
165 alter table acc_trans add foreign key (chart_id) references chart (id);
166 alter table invoice add foreign key (parts_id) references parts (id);
167 alter table ar add foreign key (customer_id) references customer (id);
168 alter table ap add foreign key (vendor_id) references vendor (id);
169 alter table orderitems add foreign key (trans_id) references oe (id);
170 alter table orderitems add foreign key (parts_id) references parts (id);
171
172 --Modify the possible length of bank account numbers
173 alter table customer add column temp_account_number character varying(15);
174 update customer set temp_account_number=account_number;
175 alter table customer drop column account_number;
176 alter table customer rename temp_account_number to  account_number;
177
178 alter table vendor add column temp_account_number character varying(15);
179 update vendor set temp_account_number=account_number;
180 alter table vendor drop column account_number;
181 alter table vendor rename temp_account_number to  account_number;
182
183 update defaults set version = '2.1.2';
184 --
185