summaryrefslogtreecommitdiff
path: root/sql-ledger/sql/Pg-upgrade-1.4.0-1.6.0.sql
blob: e0a38924654e87aa5454114ea8471c8e0c9e5fc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
alter table acc_trans rename column accno to chart_id;
update acc_trans set chart_id =
  (select id from chart where accno = acc_trans.chart_id);
--
alter table parts rename column inventory_accno to inventory_accno_id;
alter table parts rename column income_accno to income_accno_id;
alter table parts rename column expense_accno to expense_accno_id;
alter table parts rename column number to partnumber;
update parts set inventory_accno_id =
  (select id from chart where chart.accno = parts.inventory_accno_id);
update parts set income_accno_id =
  (select id from chart where chart.accno = parts.income_accno_id);
update parts set expense_accno_id =
  (select id from chart where chart.accno = parts.expense_accno_id);
--
create table assembly (id int, parts_id int, qty float);
--
alter table defaults rename column inventory_accno to inventory_accno_id;
alter table defaults rename column income_accno to income_accno_id;
alter table defaults rename column expense_accno to expense_accno_id;
alter table defaults add column businessnumber text;
alter table defaults add column version varchar(8);
update defaults set inventory_accno_id =
  (select id from chart where chart.accno = defaults.inventory_accno_id);
update defaults set income_accno_id =
  (select id from chart where chart.accno = defaults.income_accno_id);
update defaults set expense_accno_id =
  (select id from chart where chart.accno = defaults.expense_accno_id);
update defaults set version = '1.6.0';
--
alter table invoice rename column inventory_accno to inventory_accno_id;
alter table invoice rename column income_accno to income_accno_id;
alter table invoice rename column expense_accno to expense_accno_id;
alter table invoice rename column number to partnumber;
alter table invoice add column assemblyitem bool;
update invoice set assemblyitem = 'f';
update invoice set inventory_accno_id =
  (select id from chart where invoice.inventory_accno_id = chart.accno);
update invoice set income_accno_id =
  (select id from chart where invoice.income_accno_id = chart.accno);
update invoice set expense_accno_id =
  (select id from chart where invoice.expense_accno_id = chart.accno);
--
alter table gl rename column comment to description;
--
create table newvendor (
  id int default nextval ( 'id' ),
  name varchar(35),
  addr1 varchar(35),
  addr2 varchar(35),
  addr3 varchar(35),
  addr4 varchar(35),
  contact varchar(35),
  phone varchar(20),
  fax varchar(20),
  email text,
  notes text,
  terms int2,
  taxincluded bool
);
insert into newvendor (
  id, name, addr1, addr2, addr3, contact, phone, fax, email, notes, terms,
  taxincluded)
  select
  id, name, addr1, addr2, addr3, contact, phone, fax, email, notes, terms,
  taxincluded from vendor;
drop table vendor;
alter table newvendor rename to vendor;
--
create table newcustomer (
  id int default nextval ( 'id' ),
  name varchar(35),
  addr1 varchar(35),
  addr2 varchar(35),
  addr3 varchar(35),
  addr4 varchar(35),
  contact varchar(35),
  phone varchar(20),
  fax varchar(20),
  email text,
  notes text,
  discount float4,
  taxincluded bool,
  creditlimit float,
  terms int2,
  shiptoname varchar(35),
  shiptoaddr1 varchar(35),
  shiptoaddr2 varchar(35),
  shiptoaddr3 varchar(35),
  shiptoaddr4 varchar(35),
  shiptocontact varchar(20),
  shiptophone varchar(20),
  shiptofax varchar(20),
  shiptoemail text
);
insert into newcustomer (
  id, name, addr1, addr2, addr3, contact, phone, fax, email, notes, discount,
  taxincluded, creditlimit, terms, shiptoname, shiptoaddr1, shiptoaddr2,
  shiptoaddr3, shiptocontact, shiptophone, shiptofax, shiptoemail
  )
  select
  id, name, addr1, addr2, addr3, contact, phone, fax, email, notes, discount,
  taxincluded, creditlimit, terms, shiptoname, shiptoaddr1, shiptoaddr2,
  shiptoaddr3, shiptocontact, shiptophone, shiptofax, shiptoemail
  from customer;
drop table customer;
alter table newcustomer rename to customer;
--
drop index chart_accno_key;
alter table chart rename to oldchart;
create table chart (
  id int default nextval('id'),
  accno int unique,
  description text,
  charttype char(1),
  gifi int,
  category char(1),
  link text
);
insert into chart (id, accno, description, charttype, gifi, category, link)
  select id, accno, description, type, gifi, category, link from oldchart;
drop table oldchart;
--
alter table tax rename column number to taxnumber;
--
-- apply