Alle Dateien durch Perltidy laufen lassen. Die verwendeten Optionen sind am Ende...
[kivitendo-erp.git] / sql / updateLedger-200.sql
1 -- Updatescript von Version SQLedger 2.x auf 2.00
2 -- H.Lindemann Lx-System GbR
3 -- info@lx-system.de
4 -- Version: 2.3.9
5
6 BEGIN;
7 LOCK TABLE gl IN ACCESS EXCLUSIVE MODE;
8 LOCK TABLE ar IN ACCESS EXCLUSIVE MODE;
9 LOCK TABLE ap IN ACCESS EXCLUSIVE MODE;
10 LOCK TABLE vendor IN ACCESS EXCLUSIVE MODE;
11 LOCK TABLE customer IN ACCESS EXCLUSIVE MODE;
12 LOCK TABLE employee IN ACCESS EXCLUSIVE MODE;
13 LOCK TABLE shipto IN ACCESS EXCLUSIVE MODE;
14
15 CREATE SEQUENCE glid start 1 increment 1 maxvalue 9223372036854775807 minvalue 1 cache 1;
16
17 CREATE FUNCTION _glid()
18 RETURNS text
19 AS 'DECLARE lv record;
20 BEGIN
21 SELECT INTO lv last_value from id;
22 execute ''SELECT pg_catalog.setval(''''glid'''', '' || lv.last_value || '' , true)'';
23 return cast(lv.last_value as text);
24 END;'
25 LANGUAGE 'plpgsql';
26 select _glid();
27 drop function _glid();
28
29 \echo gl
30 ALTER TABLE gl ALTER COLUMN id SET DEFAULT nextval('glid'::text);
31 ALTER TABLE gl ADD COLUMN gldate date;
32 ALTER TABLE gl ALTER COLUMN gldate SET DEFAULT date('now'::text);
33 ALTER TABLE gl ADD COLUMN taxinxluded boolean;
34
35 \echo chart
36 ALTER TABLE chart ADD COLUMN taxkey_id integer;
37 ALTER TABLE chart ADD COLUMN pos_ustva integer;
38 ALTER TABLE chart ADD COLUMN pos_bwa integer;
39 ALTER TABLE chart ADD COLUMN pos_bilanz integer;
40 ALTER TABLE chart ADD COLUMN pos_eur integer;
41
42 \echo defaults
43 --ALTER TABLE defaults drop COLUMN audittrail;
44
45 \echo acc_trans
46 ALTER TABLE acc_trans ADD COLUMN taxkey integer;
47 ALTER TABLE acc_trans ADD COLUMN gldate date;
48 ALTER TABLE acc_trans ALTER COLUMN gldate SET DEFAULT date('now'::text);
49
50 \echo vendor
51 CREATE TABLE newvendor (
52     id integer DEFAULT nextval('id'::text),
53     name character varying(75),
54     street character varying(75),
55     zipcode character varying(10),
56     city character varying(75),
57     country character varying(75),
58     contact character varying(75),
59     phone character varying(30),
60     fax character varying(30),
61     homepage text,
62     email text,
63     notes text,
64     terms smallint DEFAULT 0,
65     taxincluded boolean,
66     vendornumber text,
67     cc text,
68     bcc text,
69     gifi_accno text,
70     business_id integer,
71     taxnumber text,
72     sic_code text,
73     discount real,
74     creditlimit double precision
75 );
76 INSERT INTO newvendor (
77 id, name, street,zipcode,city,country,contact,phone,fax,homepage,email,notes,terms,taxincluded,
78 vendornumber,cc,bcc,gifi_accno,business_id,taxnumber,sic_code,discount,creditlimit)
79 SELECT
80 id, name, address1,zipcode,city,country,contact,phone, fax,null,email,notes,terms,taxincluded,
81 vendornumber,cc,bcc,gifi_accno,business_id,taxnumber,sic_code,discount,creditlimit
82 FROM vendor;
83 --address2, state, iban, bic, employee_id, language_code, pricegroup_id, curr
84 DROP TABLE vendor;
85 ALTER TABLE newvendor RENAME TO vendor;
86
87 \echo customer
88 CREATE TABLE newcustomer (
89     id integer DEFAULT nextval('id'::text),
90     name character varying(75),
91     street character varying(75),
92     zipcode character varying(10),
93     city character varying(75),
94     country character varying(75),
95     contact character varying(75),
96     phone character varying(30),
97     fax character varying(30),
98     homepage text,
99     email text,
100     notes text,
101     discount real,
102     taxincluded boolean,
103     creditlimit double precision DEFAULT 0,
104     terms smallint DEFAULT 0,
105     customernumber text,
106     cc text,
107     bcc text,
108     business_id integer,
109     taxnumber text,
110     sic_code text
111 );
112 INSERT INTO newcustomer (
113 id,name,street,zipcode,city,country,contact,phone,fax,homepage,email,notes,discount,taxincluded,creditlimit,
114 terms,customernumber,cc,bcc,business_id,taxnumber,sic_code)
115 SELECT
116 id,name,address1,zipcode,city,country,contact,phone,fax,null,email,notes,discount,taxincluded,creditlimit,
117 terms,customernumber,cc,bcc,business_id,taxnumber,sic_code
118 FROM customer;
119 --address2, state, iban, bic, employee_id, language_code, pricegroup_id, curr
120 DROP TABLE customer;
121 ALTER TABLE newcustomer RENAME TO customer;
122
123 \echo contacts
124 CREATE TABLE contacts (
125     cp_id integer DEFAULT nextval('id'::text),
126     cp_cv_id integer,
127     cp_greeting character varying(75),
128     cp_title character varying(75),
129     cp_givenname character varying(75),
130     cp_name character varying(75),
131     cp_email text,
132     cp_phone1 character varying(75),
133     cp_phone2 character varying(75)
134 );
135
136 \echo parts
137 ALTER TABLE parts ADD COLUMN shop boolean;
138 ALTER TABLE parts ALTER COLUMN shop SET DEFAULT false;
139
140 \echo ar
141 ALTER TABLE ar ALTER COLUMN id SET DEFAULT nextval('glid'::text);
142 ALTER TABLE ar ADD COLUMN gldate date;
143 ALTER TABLE ar ALTER COLUMN gldate SET DEFAULT date('now'::text);
144 --ALTER TABLE ar DROP COLUMN language_code;
145 --ALTER TABLE ar DROP COLUMN till;
146
147 \echo ap
148 ALTER TABLE ap ALTER COLUMN id SET DEFAULT nextval('glid'::text);
149 ALTER TABLE ap ADD COLUMN gldate date;
150 ALTER TABLE ap ALTER COLUMN gldate SET DEFAULT date('now'::text);
151 --ALTER TABLE ap DROP COLUMN language_code;
152 --ALTER TABLE ap DROP COLUMN till;
153
154 \echo tax
155 ALTER TABLE tax ADD COLUMN taxkey integer;
156 ALTER TABLE tax ADD COLUMN taxdescription text;
157
158 \echo oe
159 ALTER TABLE oe DROP COLUMN language_code;
160
161 \echo employee
162 CREATE TABLE newemployee (
163     id integer DEFAULT nextval('id'::text),
164     login text,
165     name character varying(35),
166     addr1 character varying(35),
167     addr2 character varying(35),
168     addr3 character varying(35),
169     addr4 character varying(35),
170     workphone character varying(20),
171     homephone character varying(20),
172     startdate date DEFAULT date('now'::text),
173     enddate date,
174     notes text,
175     role text,
176     sales boolean DEFAULT true
177 );
178 INSERT INTO newemployee (
179 id,login,name,addr1,addr2,addr3,addr4,workphone,homephone,startdate,enddate,notes,role,sales)
180 SELECT
181 id,login,name,address1,zipcode,city,address2, workphone,homephone,startdate,enddate,notes,role,sales
182 FROM employee;
183 --address2,state, country, email, sin, iban, bic, managerid
184 DROP TABLE employee;
185 ALTER TABLE newemployee RENAME TO employee;
186
187 \echo shipto
188 CREATE TABLE newshipto (
189     trans_id integer,
190     shiptoname character varying(75),
191     shiptostreet character varying(75),
192     shiptozipcode character varying(75),
193     shiptocity character varying(75),
194     shiptocountry character varying(75),
195     shiptocontact character varying(75),
196     shiptophone character varying(30),
197     shiptofax character varying(30),
198     shiptoemail text
199 );
200 INSERT INTO newshipto(
201 trans_id,shiptoname,shiptostreet,shiptozipcode,shiptocity,shiptocountry,shiptocontact,shiptophone,shiptofax,shiptoemail)
202 SELECT
203 trans_id,shiptoname,shiptoaddress1,shiptozipcode,shiptocity,shiptocountry,shiptocontact,shiptophone,shiptofax,shiptoemail
204 FROM shipto;
205 -- shiptoaddress2,shiptostate,
206 DROP TABLE shipto;
207 ALTER TABLE newshipto RENAME TO shipto;
208
209 \echo sic
210 ALTER TABLE sic ADD COLUMN newcode text;
211 UPDATE sic set newcode=code;
212 ALTER TABLE sic drop COLUMN code;
213 ALTER TABLE sic RENAME COLUMN newcode TO code;
214
215 \echo yearend
216 --DROP TABLE yearend;
217
218 \echo partsvendor
219 --DROP TABLE partsvendor;
220
221 \echo pricegroup
222 --DROP TABLE pricegroup;
223
224 \echo partscustomer
225 --DROP TABLE partscustomer;
226
227 \echo language
228 --DROP TABLE language;
229
230 \echo autittrail
231 --DROP TABLE audittrail;
232
233 \echo translation;
234 --DROP TABLE translation;
235
236 \echo indexe
237 CREATE INDEX contact_name_key ON contacts USING btree (cp_name);
238
239 update defaults set version = '2.0.0';
240
241
242 end;