New files after 2.1RC merge
[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` DROP COLUMN `bank_trans_type_id`;
72 ALTER TABLE `0_bank_trans` ADD `reconciled` date default NULL;
73
74 ALTER TABLE `0_users` ADD `query_size` TINYINT(1) DEFAULT '10';
75
76 ALTER TABLE `0_users` ADD `graphic_links` TINYINT(1) DEFAULT '1';
77
78 DROP TABLE IF EXISTS `0_sales_pos`;
79
80 CREATE TABLE `0_sales_pos` (
81   `id` smallint(6) UNSIGNED NOT NULL auto_increment,
82   `pos_name` varchar(30) NOT NULL,
83   `cash_sale` tinyint(1) NOT NULL,
84   `credit_sale` tinyint(1) NOT NULL,
85   `pos_location` varchar(5) NOT NULL,
86   `pos_account` smallint(6) UNSIGNED NOT NULL,
87   `inactive` tinyint(1) NOT NULL default 0,
88   PRIMARY KEY  (`id`),
89   UNIQUE KEY(`pos_name`)
90 ) TYPE=MyISAM AUTO_INCREMENT=1;
91
92 INSERT INTO `0_sales_pos` VALUES ('1', 'Default', '1', '1', 'DEF', '1', '0');
93
94 ALTER TABLE `0_users` ADD `pos` SMALLINT(6) DEFAULT '1';
95
96 DROP TABLE IF EXISTS `0_quick_entries`;
97
98 CREATE TABLE `0_quick_entries` (
99   `id` smallint(6) UNSIGNED NOT NULL auto_increment,
100   `type` tinyint(1) NOT NULL default '0',
101   `description` varchar(60) NOT NULL,
102   `base_amount` double NOT NULL default '0',
103   `base_desc` varchar(60) NULL,
104   PRIMARY KEY  (`id`),
105   KEY `description` (`description`)
106 ) TYPE=MyISAM AUTO_INCREMENT=1;
107
108 INSERT INTO `0_quick_entries` VALUES ('1', '1', 'Maintenance', '0', 'Amount');
109 INSERT INTO `0_quick_entries` VALUES ('2', '1', 'Phone', '0', 'Amount');
110 INSERT INTO `0_quick_entries` VALUES ('3', '2', 'Cash Sales', '0', 'Amount');
111
112 DROP TABLE IF EXISTS `0_quick_entry_lines`;
113
114 CREATE TABLE `0_quick_entry_lines` (
115   `id` smallint(6) UNSIGNED NOT NULL auto_increment,
116   `qid` smallint(6) UNSIGNED NOT NULL,
117   `amount` double default NULL default '0',
118   `action` varchar(2) NOT NULL,
119   `dest_id` varchar(11) NOT NULL,
120   `dimension_id` smallint(6) UNSIGNED NULL default NULL,
121   `dimension2_id` smallint(6) UNSIGNED NULL default NULL,
122   PRIMARY KEY  (`id`),
123   KEY `qid` (`qid`)
124 ) TYPE=MyISAM AUTO_INCREMENT=1;
125
126 INSERT INTO `0_quick_entry_lines` VALUES ('1', '1','0','=', '6600', '0', '0');
127 INSERT INTO `0_quick_entry_lines` VALUES ('2', '2','0','=', '6730', '0', '0');
128 INSERT INTO `0_quick_entry_lines` VALUES ('3', '3','0','=', '3000', '0', '0');
129
130 ALTER TABLE `0_users` ADD `print_profile` VARCHAR(30) NOT NULL DEFAULT '1';
131 ALTER TABLE `0_users` ADD `rep_popup` TINYINT(1) DEFAULT '1';
132
133 DROP TABLE IF EXISTS `0_print_profiles`;
134 CREATE TABLE `0_print_profiles` (
135   `id` smallint(6) UNSIGNED NOT NULL auto_increment,
136   `profile` varchar(30) NOT NULL,
137   `report` varchar(5) NULL default NULL,
138   `printer` tinyint(3) UNSIGNED NULL default NULL,
139   PRIMARY KEY  (`id`),
140   UNIQUE KEY `profile` (`profile`,`report`)
141 ) TYPE=MyISAM AUTO_INCREMENT=10;
142
143 INSERT INTO `0_print_profiles` VALUES ('1', 'Out of office', '', '0');
144 INSERT INTO `0_print_profiles` VALUES ('2', 'Sales Department', '', '0');
145 INSERT INTO `0_print_profiles` VALUES ('3', 'Central', '', '2');
146 INSERT INTO `0_print_profiles` VALUES ('4', 'Sales Department', '104', '2');
147 INSERT INTO `0_print_profiles` VALUES ('5', 'Sales Department', '105', '2');
148 INSERT INTO `0_print_profiles` VALUES ('6', 'Sales Department', '107', '2');
149 INSERT INTO `0_print_profiles` VALUES ('7', 'Sales Department', '109', '2');
150 INSERT INTO `0_print_profiles` VALUES ('8', 'Sales Department', '110', '2');
151 INSERT INTO `0_print_profiles` VALUES ('9', 'Sales Department', '201', '2');
152
153 DROP TABLE IF EXISTS `0_printers`;
154
155 CREATE TABLE `0_printers` (
156   `id` tinyint(3) UNSIGNED NOT NULL auto_increment,
157   `name` varchar(20) NOT NULL,
158   `description` varchar(60) NOT NULL,
159   `queue` varchar(20) NOT NULL,
160   `host` varchar(40) NOT NULL,
161   `port` smallint(11) unsigned NOT NULL,
162   `timeout` tinyint(3) unsigned NOT NULL,
163   PRIMARY KEY  (`id`),
164   UNIQUE KEY `name` (`name`)
165 ) TYPE=MyISAM AUTO_INCREMENT=4;
166
167 INSERT INTO `0_printers` VALUES ('1', 'QL500', 'Label printer', 'QL500', 'server', '127', '20');
168 INSERT INTO `0_printers` VALUES ('2', 'Samsung', 'Main network printer', 'scx4521F', 'server', '515', '5');
169 INSERT INTO `0_printers` VALUES ('3', 'Local', 'Local print server at user IP', 'lp', '', '515', '10');
170
171 DROP TABLE IF EXISTS `0_item_codes`;
172
173 CREATE TABLE `0_item_codes` (
174   `id` int(11) UNSIGNED NOT NULL auto_increment,
175   `item_code` varchar(20) NOT NULL,
176   `stock_id` varchar(20) NOT NULL,
177   `description` varchar(200) NOT NULL default '',
178   `category_id` smallint(6) UNSIGNED NOT NULL,
179   `quantity` double NOT NULL default '1',
180   `is_foreign` tinyint(1) NOT NULL default 0,
181   `inactive` tinyint(1) NOT NULL default 0,
182   PRIMARY KEY  (`id`),
183   UNIQUE KEY(`stock_id`, `item_code`)
184 ) TYPE=MyISAM AUTO_INCREMENT=1;
185
186 ALTER TABLE `0_company` ADD `foreign_codes` TINYINT(1) NOT NULL DEFAULT '0';
187
188 ALTER TABLE `0_company` ADD `accumulate_shipping` TINYINT(1) NOT NULL DEFAULT '0';
189
190 ALTER TABLE `0_company` ADD `legal_text` tinytext NOT NULL DEFAULT '';
191
192 ALTER TABLE `0_suppliers` ADD `supp_address` tinytext NOT NULL DEFAULT '' AFTER `address`;
193
194 ALTER TABLE `0_suppliers` ADD `phone` varchar(30) NOT NULL DEFAULT '' AFTER `supp_address`;
195
196 ALTER TABLE `0_suppliers` ADD `fax` varchar(30) NOT NULL DEFAULT '' AFTER `phone`;
197
198 ALTER TABLE `0_suppliers` ADD `gst_no` varchar(25) NOT NULL DEFAULT '' AFTER `fax`;
199
200 ALTER TABLE `0_suppliers` ADD `contact` varchar(60) NOT NULL DEFAULT '' AFTER `gst_no`;
201
202 ALTER TABLE `0_suppliers` ADD `credit_limit` double NOT NULL DEFAULT '0' AFTER `tax_group_id`;
203
204 ALTER TABLE `0_suppliers` ADD `supp_account_no` varchar(40) NOT NULL DEFAULT '' AFTER `contact`;
205
206 ALTER TABLE `0_suppliers` ADD `website` varchar(100) NOT NULL DEFAULT '' AFTER `email`;
207
208 ALTER TABLE `0_suppliers` ADD `notes` tinytext NOT NULL DEFAULT '';
209
210 ALTER TABLE `0_chart_types` DROP INDEX `name`, ADD INDEX `name` ( `name` );
211
212 DROP TABLE IF EXISTS `0_sql_trail`; 
213
214 CREATE TABLE IF NOT EXISTS `0_sql_trail` (
215   `id` int(11) UNSIGNED NOT NULL auto_increment,
216   `sql` text NOT NULL, 
217   `result` tinyint(1) NOT NULL, 
218   `msg` varchar(255) NOT NULL,
219   PRIMARY KEY (`id`)
220 ) TYPE = MyISAM;
221
222 ALTER TABLE `0_tax_types` DROP COLUMN `out`;
223
224 ALTER TABLE `0_chart_master` DROP COLUMN `tax_code`;
225
226 ALTER TABLE `0_chart_master` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
227
228 ALTER TABLE `0_currencies` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
229
230 ALTER TABLE `0_bank_accounts` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
231
232 ALTER TABLE `0_debtors_master` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
233
234 ALTER TABLE `0_stock_master` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
235
236 ALTER TABLE `0_workcentres` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
237
238 ALTER TABLE `0_locations` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
239
240 ALTER TABLE `0_sales_types` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
241
242 ALTER TABLE `0_areas` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
243
244 ALTER TABLE `0_salesman` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
245
246 ALTER TABLE `0_shippers` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
247
248 ALTER TABLE `0_credit_status` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
249
250 ALTER TABLE `0_payment_terms` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
251
252 ALTER TABLE `0_suppliers` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
253
254 ALTER TABLE `0_stock_category` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
255
256 ALTER TABLE `0_item_units` ADD `inactive` tinyint(1) NOT NULL DEFAULT '0';
257
258 DROP TABLE IF EXISTS `0_trans_tax_details`;
259
260 CREATE TABLE `0_trans_tax_details` (
261   `id` int(11) NOT NULL auto_increment,
262   `trans_type` smallint(6) default NULL,
263   `trans_no` int(11) default NULL,
264   `tran_date` date NOT NULL,
265   `tax_type_id` int(11) NOT NULL default '0',
266   `rate` double NOT NULL default '0',
267   `ex_rate` double NOT NULL default '1',
268   `included_in_price` tinyint(1) NOT NULL default '0',
269   `net_amount` double NOT NULL default '0',
270   `amount` double NOT NULL default '0',
271   `memo` tinytext default NULL,
272   PRIMARY KEY  (`id`)
273 ) TYPE=InnoDB AUTO_INCREMENT=1 ;
274