Removed ALTER TABLE DROP columns
[fa-stable.git] / sql / alter2.1.sql
1 #
2 #       Database upgrade script Front Accounting 
3 #       Source version: 2.0.x
4 #       Target version: 2.1.0
5 #       
6 #       To make upgrades clean and failsafe:
7 #       * Precede all CREATE TABLE statment with DROP TABLE IF EXISTS
8 #       * Precede all ALTER TABLE statements using ADD column with respective
9 #               ALTER TABLE with DROP column
10 #       * Move all other DROP queries (e.g. removing obsolete tables) to installer
11 #               - they are not executed during non-forced upgrade.
12 #
13
14 DROP TABLE IF EXISTS `0_attachments`;
15
16 CREATE TABLE `0_attachments` (
17   `id` int(11) UNSIGNED NOT NULL auto_increment,
18   `description` varchar(60) NOT NULL default '',
19   `type_no` int(11) NOT NULL default '0',
20   `trans_no` int(11) NOT NULL default '0',
21   `unique_name` varchar(60) NOT NULL default '',
22   `tran_date` date NOT NULL default '0000-00-00',
23   `filename` varchar(60) NOT NULL default '',
24   `filesize` int(11) NOT NULL default '0',
25   `filetype` varchar(60) NOT NULL default '',
26   PRIMARY KEY  (`id`),
27   KEY `type_no` (`type_no`,`trans_no`)
28 ) TYPE=MyISAM AUTO_INCREMENT=1 ;
29
30 DROP TABLE IF EXISTS `0_groups`;
31
32 CREATE TABLE `0_groups` (
33   `id` smallint(6) UNSIGNED NOT NULL auto_increment,
34   `description` varchar(60) NOT NULL default '',
35   `inactive` tinyint(1) NOT NULL default 0,
36   PRIMARY KEY  (`id`),
37   UNIQUE KEY `description` (`description`)
38 ) TYPE=MyISAM AUTO_INCREMENT=1 ;
39
40 INSERT INTO `0_groups` VALUES ('1', 'Small', '0');
41 INSERT INTO `0_groups` VALUES ('2', 'Medium', '0');
42 INSERT INTO `0_groups` VALUES ('3', 'Large', '0');
43
44 DROP TABLE IF EXISTS `0_recurrent_invoices`;
45
46 CREATE TABLE `0_recurrent_invoices` (
47   `id` smallint(6) UNSIGNED NOT NULL auto_increment,
48   `description` varchar(60) NOT NULL default '',
49   `order_no` int(11) UNSIGNED NOT NULL,
50   `debtor_no` int(11) UNSIGNED NULL default NULL,
51   `group_no` smallint(6) UNSIGNED NULL default NULL,
52   `days` int(11) NOT NULL default '0',
53   `monthly` int(11) NOT NULL default '0',
54   `begin` date NOT NULL default '0000-00-00',
55   `end` date NOT NULL default '0000-00-00',
56   `last_sent` date NOT NULL default '0000-00-00',
57   PRIMARY KEY  (`id`),
58   UNIQUE KEY `description` (`description`)
59 ) TYPE=InnoDB AUTO_INCREMENT=1 ;
60
61 ALTER TABLE `0_cust_branch` ADD `group_no` int(11) NOT NULL default '0';
62
63 ALTER TABLE `0_debtor_trans` ADD `dimension_id` int(11) NOT NULL default '0';
64 ALTER TABLE `0_debtor_trans` ADD `dimension2_id` int(11) NOT NULL default '0';
65
66 ALTER TABLE `0_bank_accounts` DROP PRIMARY KEY;
67 ALTER TABLE `0_bank_accounts` ADD `id` SMALLINT(6) AUTO_INCREMENT PRIMARY KEY;
68 ALTER TABLE `0_bank_accounts` ADD `last_reconciled_date` timestamp NOT NULL default '0000-00-00';
69 ALTER TABLE `0_bank_accounts` ADD `ending_reconcile_balance` double NOT NULL default '0';
70
71 ALTER TABLE `0_bank_trans` ADD `reconciled` date default NULL;
72
73 ALTER TABLE `0_users` ADD `query_size` TINYINT(1) DEFAULT '10';
74
75 ALTER TABLE `0_users` ADD `graphic_links` TINYINT(1) DEFAULT '1';
76
77 DROP TABLE IF EXISTS `0_sales_pos`;
78
79 CREATE TABLE `0_sales_pos` (
80   `id` smallint(6) UNSIGNED NOT NULL auto_increment,
81   `pos_name` varchar(30) NOT NULL,
82   `cash_sale` tinyint(1) NOT NULL,
83   `credit_sale` tinyint(1) NOT NULL,
84   `pos_location` varchar(5) NOT NULL,
85   `pos_account` smallint(6) UNSIGNED NOT NULL,
86   `inactive` tinyint(1) NOT NULL default 0,
87   PRIMARY KEY  (`id`),
88   UNIQUE KEY(`pos_name`)
89 ) TYPE=MyISAM AUTO_INCREMENT=1;
90
91 INSERT INTO `0_sales_pos` VALUES ('1', 'Default', '1', '1', 'DEF', '1', '0');
92
93 ALTER TABLE `0_users` ADD `pos` SMALLINT(6) DEFAULT '1';
94
95 DROP TABLE IF EXISTS `0_quick_entries`;
96
97 CREATE TABLE `0_quick_entries` (
98   `id` smallint(6) UNSIGNED NOT NULL auto_increment,
99   `type` tinyint(1) NOT NULL default '0',
100   `description` varchar(60) NOT NULL,
101   `base_amount` double NOT NULL default '0',
102   `base_desc` varchar(60) NULL,
103   PRIMARY KEY  (`id`),
104   KEY `description` (`description`)
105 ) TYPE=MyISAM AUTO_INCREMENT=1;
106
107 INSERT INTO `0_quick_entries` VALUES ('1', '1', 'Maintenance', '0', 'Amount');
108 INSERT INTO `0_quick_entries` VALUES ('2', '1', 'Phone', '0', 'Amount');
109 INSERT INTO `0_quick_entries` VALUES ('3', '2', 'Cash Sales', '0', 'Amount');
110
111 DROP TABLE IF EXISTS `0_quick_entry_lines`;
112
113 CREATE TABLE `0_quick_entry_lines` (
114   `id` smallint(6) UNSIGNED NOT NULL auto_increment,
115   `qid` smallint(6) UNSIGNED NOT NULL,
116   `amount` double default NULL default '0',
117   `action` varchar(2) NOT NULL,
118   `dest_id` varchar(11) NOT NULL,
119   `dimension_id` smallint(6) UNSIGNED NULL default NULL,
120   `dimension2_id` smallint(6) UNSIGNED NULL default NULL,
121   PRIMARY KEY  (`id`),
122   KEY `qid` (`qid`)
123 ) TYPE=MyISAM AUTO_INCREMENT=1;
124
125 INSERT INTO `0_quick_entry_lines` VALUES ('1', '1','0','=', '6600', '0', '0');
126 INSERT INTO `0_quick_entry_lines` VALUES ('2', '2','0','=', '6730', '0', '0');
127 INSERT INTO `0_quick_entry_lines` VALUES ('3', '3','0','=', '3000', '0', '0');
128
129 ALTER TABLE `0_users` ADD `print_profile` VARCHAR(30) NOT NULL DEFAULT '1';
130 ALTER TABLE `0_users` ADD `rep_popup` TINYINT(1) DEFAULT '1';
131
132 DROP TABLE IF EXISTS `0_print_profiles`;
133 CREATE TABLE `0_print_profiles` (
134   `id` smallint(6) UNSIGNED NOT NULL auto_increment,
135   `profile` varchar(30) NOT NULL,
136   `report` varchar(5) NULL default NULL,
137   `printer` tinyint(3) UNSIGNED NULL default NULL,
138   PRIMARY KEY  (`id`),
139   UNIQUE KEY `profile` (`profile`,`report`)
140 ) TYPE=MyISAM AUTO_INCREMENT=10;
141
142 INSERT INTO `0_print_profiles` VALUES ('1', 'Out of office', '', '0');
143 INSERT INTO `0_print_profiles` VALUES ('2', 'Sales Department', '', '0');
144 INSERT INTO `0_print_profiles` VALUES ('3', 'Central', '', '2');
145 INSERT INTO `0_print_profiles` VALUES ('4', 'Sales Department', '104', '2');
146 INSERT INTO `0_print_profiles` VALUES ('5', 'Sales Department', '105', '2');
147 INSERT INTO `0_print_profiles` VALUES ('6', 'Sales Department', '107', '2');
148 INSERT INTO `0_print_profiles` VALUES ('7', 'Sales Department', '109', '2');
149 INSERT INTO `0_print_profiles` VALUES ('8', 'Sales Department', '110', '2');
150 INSERT INTO `0_print_profiles` VALUES ('9', 'Sales Department', '201', '2');
151
152 DROP TABLE IF EXISTS `0_printers`;
153
154 CREATE TABLE `0_printers` (
155   `id` tinyint(3) UNSIGNED NOT NULL auto_increment,
156   `name` varchar(20) NOT NULL,
157   `description` varchar(60) NOT NULL,
158   `queue` varchar(20) NOT NULL,
159   `host` varchar(40) NOT NULL,
160   `port` smallint(11) unsigned NOT NULL,
161   `timeout` tinyint(3) unsigned NOT NULL,
162   PRIMARY KEY  (`id`),
163   UNIQUE KEY `name` (`name`)
164 ) TYPE=MyISAM AUTO_INCREMENT=4;
165
166 INSERT INTO `0_printers` VALUES ('1', 'QL500', 'Label printer', 'QL500', 'server', '127', '20');
167 INSERT INTO `0_printers` VALUES ('2', 'Samsung', 'Main network printer', 'scx4521F', 'server', '515', '5');
168 INSERT INTO `0_printers` VALUES ('3', 'Local', 'Local print server at user IP', 'lp', '', '515', '10');
169
170 DROP TABLE IF EXISTS `0_item_codes`;
171
172 CREATE TABLE `0_item_codes` (
173   `id` int(11) UNSIGNED NOT NULL auto_increment,
174   `item_code` varchar(20) NOT NULL,
175   `stock_id` varchar(20) NOT NULL,
176   `description` varchar(200) NOT NULL default '',
177   `category_id` smallint(6) UNSIGNED NOT NULL,
178   `quantity` double NOT NULL default '1',
179   `is_foreign` tinyint(1) NOT NULL default 0,
180   `inactive` tinyint(1) NOT NULL default 0,
181   PRIMARY KEY  (`id`),
182   UNIQUE KEY(`stock_id`, `item_code`)
183 ) TYPE=MyISAM AUTO_INCREMENT=1;
184
185 ALTER TABLE `0_company` ADD `foreign_codes` TINYINT(1) NOT NULL DEFAULT '0';
186
187 ALTER TABLE `0_company` ADD `accumulate_shipping` TINYINT(1) NOT NULL DEFAULT '0';
188
189 ALTER TABLE `0_company` ADD `legal_text` tinytext NOT NULL DEFAULT '';
190
191 ALTER TABLE `0_suppliers` ADD `supp_address` tinytext NOT NULL DEFAULT '' AFTER `address`;
192
193 ALTER TABLE `0_suppliers` ADD `phone` varchar(30) NOT NULL DEFAULT '' AFTER `supp_address`;
194
195 ALTER TABLE `0_suppliers` ADD `fax` varchar(30) NOT NULL DEFAULT '' AFTER `phone`;
196
197 ALTER TABLE `0_suppliers` ADD `gst_no` varchar(25) NOT NULL DEFAULT '' AFTER `fax`;
198
199 ALTER TABLE `0_suppliers` ADD `contact` varchar(60) NOT NULL DEFAULT '' AFTER `gst_no`;
200
201 ALTER TABLE `0_suppliers` ADD `credit_limit` double NOT NULL DEFAULT '0' AFTER `tax_group_id`;
202
203 ALTER TABLE `0_suppliers` ADD `supp_account_no` varchar(40) NOT NULL DEFAULT '' AFTER `contact`;
204
205 ALTER TABLE `0_suppliers` ADD `website` varchar(100) NOT NULL DEFAULT '' AFTER `email`;
206
207 ALTER TABLE `0_suppliers` ADD `notes` tinytext NOT NULL DEFAULT '';
208
209 ALTER TABLE `0_chart_types` DROP INDEX `name`, ADD INDEX `name` ( `name` );
210
211 DROP TABLE IF EXISTS `0_sql_trail`; 
212
213 CREATE TABLE IF NOT EXISTS `0_sql_trail` (
214   `id` int(11) UNSIGNED NOT NULL auto_increment,
215   `sql` text NOT NULL, 
216   `result` tinyint(1) NOT NULL, 
217   `msg` varchar(255) NOT NULL,
218   PRIMARY KEY (`id`)
219 ) TYPE = MyISAM;
220
221 ALTER TABLE `0_tax_types` DROP COLUMN `out`;
222
223 ALTER TABLE `0_chart_master` DROP COLUMN `tax_code`;
224
225 ALTER TABLE `0_chart_master` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
226
227 ALTER TABLE `0_currencies` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
228
229 ALTER TABLE `0_bank_accounts` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
230
231 ALTER TABLE `0_debtors_master` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
232
233 ALTER TABLE `0_stock_master` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
234
235 ALTER TABLE `0_workcentres` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
236
237 ALTER TABLE `0_locations` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
238
239 ALTER TABLE `0_sales_types` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
240
241 ALTER TABLE `0_areas` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
242
243 ALTER TABLE `0_salesman` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
244
245 ALTER TABLE `0_shippers` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
246
247 ALTER TABLE `0_credit_status` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
248
249 ALTER TABLE `0_payment_terms` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
250
251 ALTER TABLE `0_suppliers` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
252
253 ALTER TABLE `0_stock_category` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
254
255 ALTER TABLE `0_item_units` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
256
257 DROP TABLE IF EXISTS `0_trans_tax_details`;
258
259 CREATE TABLE `0_trans_tax_details` (
260   `id` int(11) NOT NULL auto_increment,
261   `trans_type` smallint(6) default NULL,
262   `trans_no` int(11) default NULL,
263   `tran_date` date NOT NULL,
264   `tax_type_id` int(11) NOT NULL default '0',
265   `rate` double NOT NULL default '0',
266   `ex_rate` double NOT NULL default '1',
267   `included_in_price` tinyint(1) NOT NULL default '0',
268   `net_amount` double NOT NULL default '0',
269   `amount` double NOT NULL default '0',
270   `memo` tinytext default NULL,
271   PRIMARY KEY  (`id`)
272 ) TYPE=InnoDB AUTO_INCREMENT=1 ;
273