Permalink
Newer
Older
100644 248 lines (190 sloc) 9.14 KB
1
-- Roundcube Webmail update script for MySQL databases
2
3
-- Updates from version 0.1-stable
5
TRUNCATE TABLE `messages`;
6
8
DROP INDEX `idx`,
9
DROP INDEX `uid`;
11
ALTER TABLE `cache`
12
DROP INDEX `cache_key`,
13
DROP INDEX `session_id`,
14
ADD INDEX `user_cache_index` (`user_id`,`cache_key`);
@alecpl
Apr 3, 2008
15
16
ALTER TABLE `users`
@alecpl
Apr 5, 2008
17
ADD INDEX `username_index` (`username`),
@alecpl
Apr 3, 2008
18
ADD INDEX `alias_index` (`alias`);
19
20
-- Updates from version 0.1.1
21
22
ALTER TABLE `identities`
23
MODIFY `signature` text,
24
MODIFY `bcc` varchar(128) NOT NULL DEFAULT '',
25
MODIFY `reply-to` varchar(128) NOT NULL DEFAULT '',
26
MODIFY `organization` varchar(128) NOT NULL DEFAULT '',
27
MODIFY `name` varchar(128) NOT NULL,
28
MODIFY `email` varchar(128) NOT NULL;
29
30
-- Updates from version 0.2-alpha
31
32
ALTER TABLE `messages`
33
ADD INDEX `created_index` (`created`);
35
-- Updates from version 0.2-beta (InnoDB required)
40
ALTER TABLE `session`
41
ADD INDEX `changed_index` (`changed`);
42
43
ALTER TABLE `cache`
44
ADD INDEX `created_index` (`created`);
45
46
ALTER TABLE `users`
47
CHANGE `language` `language` varchar(5);
49
ALTER TABLE `cache` ENGINE=InnoDB;
50
ALTER TABLE `session` ENGINE=InnoDB;
51
ALTER TABLE `messages` ENGINE=InnoDB;
52
ALTER TABLE `users` ENGINE=InnoDB;
53
ALTER TABLE `contacts` ENGINE=InnoDB;
54
ALTER TABLE `identities` ENGINE=InnoDB;
55
56
-- Updates from version 0.3-stable
57
58
TRUNCATE `messages`;
59
60
ALTER TABLE `messages`
61
ADD INDEX `index_index` (`user_id`, `cache_key`, `idx`);
63
ALTER TABLE `session`
64
CHANGE `vars` `vars` MEDIUMTEXT NOT NULL;
65
66
ALTER TABLE `contacts`
67
ADD INDEX `user_contacts_index` (`user_id`,`email`);
68
69
-- Updates from version 0.3.1
70
-- WARNING: Make sure that all tables are using InnoDB engine!!!
71
-- If not, use: ALTER TABLE xxx ENGINE=InnoDB;
72
73
/* MySQL bug workaround: http://bugs.mysql.com/bug.php?id=46293 */
@alecpl
Feb 6, 2010
74
/*!40014 SET FOREIGN_KEY_CHECKS=0 */;
75
76
ALTER TABLE `messages` DROP FOREIGN KEY `user_id_fk_messages`;
77
ALTER TABLE `cache` DROP FOREIGN KEY `user_id_fk_cache`;
78
ALTER TABLE `contacts` DROP FOREIGN KEY `user_id_fk_contacts`;
79
ALTER TABLE `identities` DROP FOREIGN KEY `user_id_fk_identities`;
80
81
ALTER TABLE `messages` ADD CONSTRAINT `user_id_fk_messages` FOREIGN KEY (`user_id`)
82
REFERENCES `users`(`user_id`) ON DELETE CASCADE ON UPDATE CASCADE;
83
ALTER TABLE `cache` ADD CONSTRAINT `user_id_fk_cache` FOREIGN KEY (`user_id`)
84
REFERENCES `users`(`user_id`) ON DELETE CASCADE ON UPDATE CASCADE;
85
ALTER TABLE `contacts` ADD CONSTRAINT `user_id_fk_contacts` FOREIGN KEY (`user_id`)
86
REFERENCES `users`(`user_id`) ON DELETE CASCADE ON UPDATE CASCADE;
87
ALTER TABLE `identities` ADD CONSTRAINT `user_id_fk_identities` FOREIGN KEY (`user_id`)
88
REFERENCES `users`(`user_id`) ON DELETE CASCADE ON UPDATE CASCADE;
90
ALTER TABLE `contacts` ALTER `name` SET DEFAULT '';
91
ALTER TABLE `contacts` ALTER `firstname` SET DEFAULT '';
92
ALTER TABLE `contacts` ALTER `surname` SET DEFAULT '';
93
@alecpl
Mar 9, 2010
94
ALTER TABLE `identities` ADD INDEX `user_identities_index` (`user_id`, `del`);
95
ALTER TABLE `identities` ADD `changed` datetime NOT NULL DEFAULT '1000-01-01 00:00:00' AFTER `user_id`;
97
CREATE TABLE `contactgroups` (
98
`contactgroup_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
99
`user_id` int(10) UNSIGNED NOT NULL DEFAULT '0',
100
`changed` datetime NOT NULL DEFAULT '1000-01-01 00:00:00',
101
`del` tinyint(1) NOT NULL DEFAULT '0',
102
`name` varchar(128) NOT NULL DEFAULT '',
103
PRIMARY KEY(`contactgroup_id`),
104
CONSTRAINT `user_id_fk_contactgroups` FOREIGN KEY (`user_id`)
105
REFERENCES `users`(`user_id`) ON DELETE CASCADE ON UPDATE CASCADE,
106
INDEX `contactgroups_user_index` (`user_id`,`del`)
107
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
108
109
CREATE TABLE `contactgroupmembers` (
110
`contactgroup_id` int(10) UNSIGNED NOT NULL,
111
`contact_id` int(10) UNSIGNED NOT NULL DEFAULT '0',
112
`created` datetime NOT NULL DEFAULT '1000-01-01 00:00:00',
113
PRIMARY KEY (`contactgroup_id`, `contact_id`),
114
CONSTRAINT `contactgroup_id_fk_contactgroups` FOREIGN KEY (`contactgroup_id`)
115
REFERENCES `contactgroups`(`contactgroup_id`) ON DELETE CASCADE ON UPDATE CASCADE,
116
CONSTRAINT `contact_id_fk_contacts` FOREIGN KEY (`contact_id`)
117
REFERENCES `contacts`(`contact_id`) ON DELETE CASCADE ON UPDATE CASCADE
118
) /*!40000 ENGINE=INNODB */;
119
@alecpl
Feb 6, 2010
120
/*!40014 SET FOREIGN_KEY_CHECKS=1 */;
121
122
-- Updates from version 0.4-beta
123
124
ALTER TABLE `users` CHANGE `last_login` `last_login` datetime DEFAULT NULL;
125
UPDATE `users` SET `last_login` = NULL WHERE `last_login` = '1000-01-01 00:00:00';
126
127
-- Updates from version 0.4.2
128
129
ALTER TABLE `users` DROP INDEX `username_index`;
130
ALTER TABLE `users` ADD UNIQUE `username` (`username`, `mail_host`);
131
132
ALTER TABLE `contacts` MODIFY `email` varchar(255) NOT NULL;
133
134
TRUNCATE TABLE `messages`;
135
136
-- Updates from version 0.5.1
137
-- Updates from version 0.5.2
138
-- Updates from version 0.5.3
139
-- Updates from version 0.5.4
140
141
ALTER TABLE `contacts` ADD `words` TEXT NULL AFTER `vcard`;
142
ALTER TABLE `contacts` CHANGE `vcard` `vcard` LONGTEXT /*!40101 CHARACTER SET utf8 */ NULL DEFAULT NULL;
143
ALTER TABLE `contactgroupmembers` ADD INDEX `contactgroupmembers_contact_index` (`contact_id`);
144
145
TRUNCATE TABLE `messages`;
146
TRUNCATE TABLE `cache`;
148
-- Updates from version 0.6
150
/*!40014 SET FOREIGN_KEY_CHECKS=0 */;
151
152
ALTER TABLE `users` CHANGE `alias` `alias` varchar(128) BINARY NOT NULL;
153
ALTER TABLE `users` CHANGE `username` `username` varchar(128) BINARY NOT NULL;
154
155
CREATE TABLE `dictionary` (
156
`user_id` int(10) UNSIGNED DEFAULT NULL,
157
`language` varchar(5) NOT NULL,
158
`data` longtext NOT NULL,
159
CONSTRAINT `user_id_fk_dictionary` FOREIGN KEY (`user_id`)
160
REFERENCES `users`(`user_id`) ON DELETE CASCADE ON UPDATE CASCADE,
161
UNIQUE `uniqueness` (`user_id`, `language`)
162
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
163
164
CREATE TABLE `searches` (
165
`search_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
166
`user_id` int(10) UNSIGNED NOT NULL DEFAULT '0',
167
`type` int(3) NOT NULL DEFAULT '0',
168
`name` varchar(128) NOT NULL,
169
`data` text,
170
PRIMARY KEY(`search_id`),
171
CONSTRAINT `user_id_fk_searches` FOREIGN KEY (`user_id`)
172
REFERENCES `users`(`user_id`) ON DELETE CASCADE ON UPDATE CASCADE,
173
UNIQUE `uniqueness` (`user_id`, `type`, `name`)
174
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
175
176
DROP TABLE `messages`;
177
178
CREATE TABLE `cache_index` (
179
`user_id` int(10) UNSIGNED NOT NULL DEFAULT '0',
180
`mailbox` varchar(255) BINARY NOT NULL,
181
`changed` datetime NOT NULL DEFAULT '1000-01-01 00:00:00',
182
`valid` tinyint(1) NOT NULL DEFAULT '0',
183
`data` longtext NOT NULL,
184
CONSTRAINT `user_id_fk_cache_index` FOREIGN KEY (`user_id`)
185
REFERENCES `users`(`user_id`) ON DELETE CASCADE ON UPDATE CASCADE,
186
INDEX `changed_index` (`changed`),
187
PRIMARY KEY (`user_id`, `mailbox`)
188
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
189
190
CREATE TABLE `cache_thread` (
191
`user_id` int(10) UNSIGNED NOT NULL DEFAULT '0',
192
`mailbox` varchar(255) BINARY NOT NULL,
193
`changed` datetime NOT NULL DEFAULT '1000-01-01 00:00:00',
194
`data` longtext NOT NULL,
195
CONSTRAINT `user_id_fk_cache_thread` FOREIGN KEY (`user_id`)
196
REFERENCES `users`(`user_id`) ON DELETE CASCADE ON UPDATE CASCADE,
197
INDEX `changed_index` (`changed`),
198
PRIMARY KEY (`user_id`, `mailbox`)
199
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
200
201
CREATE TABLE `cache_messages` (
202
`user_id` int(10) UNSIGNED NOT NULL DEFAULT '0',
203
`mailbox` varchar(255) BINARY NOT NULL,
204
`uid` int(11) UNSIGNED NOT NULL DEFAULT '0',
205
`changed` datetime NOT NULL DEFAULT '1000-01-01 00:00:00',
206
`data` longtext NOT NULL,
207
`flags` int(11) NOT NULL DEFAULT '0',
208
CONSTRAINT `user_id_fk_cache_messages` FOREIGN KEY (`user_id`)
209
REFERENCES `users`(`user_id`) ON DELETE CASCADE ON UPDATE CASCADE,
210
INDEX `changed_index` (`changed`),
211
PRIMARY KEY (`user_id`, `mailbox`, `uid`)
212
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */;
214
/*!40014 SET FOREIGN_KEY_CHECKS=1 */;
215
216
-- Updates from version 0.7-beta
217
218
ALTER TABLE `session` CHANGE `sess_id` `sess_id` varchar(128) NOT NULL;
219
220
-- Updates from version 0.7
221
222
/*!40014 SET FOREIGN_KEY_CHECKS=0 */;
223
224
ALTER TABLE `contacts` DROP FOREIGN KEY `user_id_fk_contacts`;
225
ALTER TABLE `contacts` DROP INDEX `user_contacts_index`;
226
ALTER TABLE `contacts` MODIFY `email` text NOT NULL;
227
ALTER TABLE `contacts` ADD INDEX `user_contacts_index` (`user_id`,`del`);
228
ALTER TABLE `contacts` ADD CONSTRAINT `user_id_fk_contacts` FOREIGN KEY (`user_id`)
229
REFERENCES `users`(`user_id`) ON DELETE CASCADE ON UPDATE CASCADE;
230
231
ALTER TABLE `cache` ALTER `user_id` DROP DEFAULT;
232
ALTER TABLE `cache_index` ALTER `user_id` DROP DEFAULT;
233
ALTER TABLE `cache_thread` ALTER `user_id` DROP DEFAULT;
234
ALTER TABLE `cache_messages` ALTER `user_id` DROP DEFAULT;
235
ALTER TABLE `contacts` ALTER `user_id` DROP DEFAULT;
236
ALTER TABLE `contactgroups` ALTER `user_id` DROP DEFAULT;
237
ALTER TABLE `contactgroupmembers` ALTER `contact_id` DROP DEFAULT;
238
ALTER TABLE `identities` ALTER `user_id` DROP DEFAULT;
239
ALTER TABLE `searches` ALTER `user_id` DROP DEFAULT;
240
241
/*!40014 SET FOREIGN_KEY_CHECKS=1 */;
242
243
-- Updates from version 0.8
244
245
ALTER TABLE `cache` DROP COLUMN `cache_id`;
246
ALTER TABLE `users` DROP COLUMN `alias`;
247
ALTER TABLE `identities` ADD INDEX `email_identities_index` (`email`, `del`);