aboutsummaryrefslogtreecommitdiff
path: root/sql/mysql.old-to-new.sql
blob: 9614d55a84590fbc279489107bd029497c6fcdb6 (plain) (blame)
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
SET @DEFAULT_HOST = ''; -- Please fill with name of your current host name

BEGIN;
DELIMITER ##
CREATE PROCEDURE update_server_host(IN DEFAULT_HOST TEXT)
BEGIN
        START TRANSACTION;
        SET FOREIGN_KEY_CHECKS = 0;
        SET @DEFAULT_HOST = DEFAULT_HOST;
        IF DEFAULT_HOST = '' THEN
                SELECT 'Please fill @DEFAULT_HOST parameter' as Error;
                ROLLBACK;
        ELSE
                ALTER TABLE `push_session` DROP INDEX `i_push_usn`;
                ALTER TABLE `push_session` DROP INDEX `i_push_ut`;
                ALTER TABLE `push_session` ADD COLUMN `server_host` VARCHAR (191) NOT NULL DEFAULT @DEFAULT_HOST AFTER `username`;
                ALTER TABLE `push_session` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `push_session` ADD PRIMARY KEY (`server_host`, `username`(191), `timestamp`);
                ALTER TABLE `push_session` ADD UNIQUE INDEX `i_push_session_susn` (`server_host`, `username`(191), `service`(191), `node`(191));
                ALTER TABLE `roster_version` DROP PRIMARY KEY;
                ALTER TABLE `roster_version` ADD COLUMN `server_host` VARCHAR (191) COLLATE `utf8mb4_unicode_ci` NOT NULL DEFAULT @DEFAULT_HOST AFTER `username`;
                ALTER TABLE `roster_version` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `roster_version` ADD PRIMARY KEY (`server_host`, `username`);
                ALTER TABLE `muc_online_room` ADD COLUMN `server_host` VARCHAR (191) COLLATE `utf8mb4_unicode_ci` NOT NULL DEFAULT @DEFAULT_HOST AFTER `host`;
                ALTER TABLE `muc_online_room` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `motd` DROP PRIMARY KEY;
                ALTER TABLE `motd` ADD COLUMN `server_host` VARCHAR (191) COLLATE `utf8mb4_unicode_ci` NOT NULL DEFAULT @DEFAULT_HOST AFTER `username`;
                ALTER TABLE `motd` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `motd` ADD PRIMARY KEY (`server_host`, `username`);
                ALTER TABLE `rosterusers` DROP INDEX `i_rosteru_username`;
                ALTER TABLE `rosterusers` DROP INDEX `i_rosteru_jid`;
                ALTER TABLE `rosterusers` DROP INDEX `i_rosteru_user_jid`;
                ALTER TABLE `rosterusers` ADD COLUMN `server_host` VARCHAR (191) COLLATE `utf8mb4_unicode_ci` NOT NULL DEFAULT @DEFAULT_HOST AFTER `username`;
                ALTER TABLE `rosterusers` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `rosterusers` ADD UNIQUE INDEX `i_rosteru_sh_user_jid` (`server_host`, `username`(75), `jid`(75));
                ALTER TABLE `rosterusers` ADD INDEX `i_rosteru_sh_username` (`server_host`, `username`);
                ALTER TABLE `rosterusers` ADD INDEX `i_rosteru_sh_jid` (`server_host`, `jid`);
                ALTER TABLE `private_storage` DROP INDEX `i_private_storage_username_namespace`;
                ALTER TABLE `private_storage` DROP INDEX `i_private_storage_username`;
                ALTER TABLE `private_storage` ADD COLUMN `server_host` VARCHAR (191) COLLATE `utf8mb4_unicode_ci` NOT NULL DEFAULT @DEFAULT_HOST AFTER `username`;
                ALTER TABLE `private_storage` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `private_storage` ADD PRIMARY KEY (`server_host`, `username`, `namespace`);
                ALTER TABLE `private_storage` ADD INDEX `i_private_storage_sh_username` USING BTREE (`server_host`, `username`);
                ALTER TABLE `mqtt_pub` DROP INDEX `i_mqtt_topic`;
                ALTER TABLE `mqtt_pub` ADD COLUMN `server_host` VARCHAR (191) NOT NULL DEFAULT @DEFAULT_HOST AFTER `username`;
                ALTER TABLE `mqtt_pub` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `mqtt_pub` ADD UNIQUE INDEX `i_mqtt_topic_server` (`topic`(191), `server_host`);
                ALTER TABLE `vcard_search` DROP PRIMARY KEY;
                ALTER TABLE `vcard_search` DROP INDEX `i_vcard_search_lgiven`;
                ALTER TABLE `vcard_search` DROP INDEX `i_vcard_search_lmiddle`;
                ALTER TABLE `vcard_search` DROP INDEX `i_vcard_search_lnickname`;
                ALTER TABLE `vcard_search` DROP INDEX `i_vcard_search_lbday`;
                ALTER TABLE `vcard_search` DROP INDEX `i_vcard_search_lctry`;
                ALTER TABLE `vcard_search` DROP INDEX `i_vcard_search_lfn`;
                ALTER TABLE `vcard_search` DROP INDEX `i_vcard_search_lemail`;
                ALTER TABLE `vcard_search` DROP INDEX `i_vcard_search_lorgunit`;
                ALTER TABLE `vcard_search` DROP INDEX `i_vcard_search_llocality`;
                ALTER TABLE `vcard_search` DROP INDEX `i_vcard_search_lorgname`;
                ALTER TABLE `vcard_search` DROP INDEX `i_vcard_search_lfamily`;
                ALTER TABLE `vcard_search` ADD COLUMN `server_host` VARCHAR (191) COLLATE `utf8mb4_unicode_ci` NOT NULL DEFAULT @DEFAULT_HOST AFTER `lusername`;
                ALTER TABLE `vcard_search` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `vcard_search` ADD INDEX `i_vcard_search_sh_lfn` (`server_host`, `lfn`);
                ALTER TABLE `vcard_search` ADD INDEX `i_vcard_search_sh_llocality` (`server_host`, `llocality`);
                ALTER TABLE `vcard_search` ADD PRIMARY KEY (`server_host`, `lusername`);
                ALTER TABLE `vcard_search` ADD INDEX `i_vcard_search_sh_lnickname` (`server_host`, `lnickname`);
                ALTER TABLE `vcard_search` ADD INDEX `i_vcard_search_sh_lctry` (`server_host`, `lctry`);
                ALTER TABLE `vcard_search` ADD INDEX `i_vcard_search_sh_lgiven` (`server_host`, `lgiven`);
                ALTER TABLE `vcard_search` ADD INDEX `i_vcard_search_sh_lmiddle` (`server_host`, `lmiddle`);
                ALTER TABLE `vcard_search` ADD INDEX `i_vcard_search_sh_lorgname` (`server_host`, `lorgname`);
                ALTER TABLE `vcard_search` ADD INDEX `i_vcard_search_sh_lfamily` (`server_host`, `lfamily`);
                ALTER TABLE `vcard_search` ADD INDEX `i_vcard_search_sh_lbday` (`server_host`, `lbday`);
                ALTER TABLE `vcard_search` ADD INDEX `i_vcard_search_sh_lemail` (`server_host`, `lemail`);
                ALTER TABLE `vcard_search` ADD INDEX `i_vcard_search_sh_lorgunit` (`server_host`, `lorgunit`);
                ALTER TABLE `last` DROP PRIMARY KEY;
                ALTER TABLE `last` ADD COLUMN `server_host` VARCHAR (191) COLLATE `utf8mb4_unicode_ci` NOT NULL DEFAULT @DEFAULT_HOST AFTER `username`;
                ALTER TABLE `last` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `last` ADD PRIMARY KEY (`server_host`, `username`);
                ALTER TABLE `sr_group` ADD COLUMN `server_host` VARCHAR (191) COLLATE `utf8mb4_unicode_ci` NOT NULL DEFAULT @DEFAULT_HOST AFTER `name`;
                ALTER TABLE `sr_group` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `sr_group` ADD UNIQUE INDEX `i_sr_group_sh_name` (`server_host`, `name`);
                ALTER TABLE `sr_group` ADD PRIMARY KEY (`server_host`, `name`);
                ALTER TABLE `muc_registered` ADD COLUMN `server_host` VARCHAR (191) COLLATE `utf8mb4_unicode_ci` NOT NULL DEFAULT @DEFAULT_HOST AFTER `host`;
                ALTER TABLE `muc_registered` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `sm` DROP INDEX `i_node`;
                ALTER TABLE `sm` DROP INDEX `i_username`;
                ALTER TABLE `sm` DROP INDEX `i_sid`;
                ALTER TABLE `sm` ADD COLUMN `server_host` VARCHAR (191) COLLATE `utf8mb4_unicode_ci` NOT NULL DEFAULT @DEFAULT_HOST AFTER `username`;
                ALTER TABLE `sm` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `sm` ADD INDEX `i_sm_node` (`node`(75));
                ALTER TABLE `sm` ADD INDEX `i_sm_sh_username` (`server_host`, `username`);
                ALTER TABLE `sm` ADD PRIMARY KEY (`usec`, `pid`(75));
                ALTER TABLE `privacy_list` DROP INDEX `i_privacy_list_username_name`;
                ALTER TABLE `privacy_list` DROP INDEX `i_privacy_list_username`;
                ALTER TABLE `privacy_list` ADD COLUMN `server_host` VARCHAR (191) COLLATE `utf8mb4_unicode_ci` NOT NULL DEFAULT @DEFAULT_HOST AFTER `username`;
                ALTER TABLE `privacy_list` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `privacy_list` ADD UNIQUE INDEX `i_privacy_list_sh_username_name` USING BTREE (`server_host`, `username`(75), `name`(75));
                ALTER TABLE `privacy_list` ADD INDEX `i_privacy_list_sh_username` USING BTREE (`server_host`, `username`);
                ALTER TABLE `sr_user` DROP INDEX `i_sr_user_jid`;
                ALTER TABLE `sr_user` DROP INDEX `i_sr_user_grp`;
                ALTER TABLE `sr_user` DROP INDEX `i_sr_user_jid_group`;
                ALTER TABLE `sr_user` ADD COLUMN `server_host` VARCHAR (191) COLLATE `utf8mb4_unicode_ci` NOT NULL DEFAULT @DEFAULT_HOST AFTER `jid`;
                ALTER TABLE `sr_user` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `sr_user` ADD UNIQUE INDEX `i_sr_user_sh_jid_group` (`server_host`, `jid`, `grp`);
                ALTER TABLE `sr_user` ADD INDEX `i_sr_user_sh_jid` (`server_host`, `jid`);
                ALTER TABLE `sr_user` ADD INDEX `i_sr_user_sh_grp` (`server_host`, `grp`);
                ALTER TABLE `sr_user` ADD PRIMARY KEY (`server_host`, `jid`, `grp`);
                ALTER TABLE `muc_online_users` ADD COLUMN `server_host` VARCHAR (191) COLLATE `utf8mb4_unicode_ci` NOT NULL DEFAULT @DEFAULT_HOST AFTER `host`;
                ALTER TABLE `muc_online_users` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `vcard` DROP PRIMARY KEY;
                ALTER TABLE `vcard` ADD COLUMN `server_host` VARCHAR (191) COLLATE `utf8mb4_unicode_ci` NOT NULL DEFAULT @DEFAULT_HOST AFTER `username`;
                ALTER TABLE `vcard` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `vcard` ADD PRIMARY KEY (`server_host`, `username`);
                ALTER TABLE `archive_prefs` DROP PRIMARY KEY;
                ALTER TABLE `archive_prefs` ADD COLUMN `server_host` VARCHAR (191) COLLATE `utf8mb4_unicode_ci` NOT NULL DEFAULT @DEFAULT_HOST AFTER `username`;
                ALTER TABLE `archive_prefs` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `archive_prefs` ADD PRIMARY KEY (`server_host`, `username`);
                ALTER TABLE `mix_pam` DROP INDEX `i_mix_pam`;
                ALTER TABLE `mix_pam` DROP INDEX `i_mix_pam_u`;
                ALTER TABLE `mix_pam` ADD COLUMN `server_host` VARCHAR (191) COLLATE `utf8mb4_unicode_ci` NOT NULL DEFAULT @DEFAULT_HOST AFTER `username`;
                ALTER TABLE `mix_pam` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `mix_pam` ADD UNIQUE INDEX `i_mix_pam` (`username`(191), `server_host`, `channel`(191), `service`(191));
                ALTER TABLE `mix_pam` ADD INDEX `i_mix_pam_us` (`username`(191), `server_host`);
                ALTER TABLE `route` CHANGE COLUMN `server_host` `server_host` VARCHAR (191) COLLATE `utf8mb4_unicode_ci` NOT NULL;
                ALTER TABLE `users` DROP PRIMARY KEY;
                ALTER TABLE `users` ADD COLUMN `server_host` VARCHAR (191) COLLATE `utf8mb4_unicode_ci` NOT NULL DEFAULT @DEFAULT_HOST AFTER `username`;
                ALTER TABLE `users` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `users` ADD PRIMARY KEY (`server_host`, `username`);
                ALTER TABLE `privacy_default_list` DROP PRIMARY KEY;
                ALTER TABLE `privacy_default_list` ADD COLUMN `server_host` VARCHAR (191) COLLATE `utf8mb4_unicode_ci` NOT NULL DEFAULT @DEFAULT_HOST AFTER `username`;
                ALTER TABLE `privacy_default_list` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `privacy_default_list` ADD PRIMARY KEY (`server_host`, `username`);
                ALTER TABLE `rostergroups` DROP INDEX `pk_rosterg_user_jid`;
                ALTER TABLE `rostergroups` ADD COLUMN `server_host` VARCHAR (191) COLLATE `utf8mb4_unicode_ci` NOT NULL DEFAULT @DEFAULT_HOST AFTER `username`;
                ALTER TABLE `rostergroups` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `rostergroups` ADD INDEX `i_rosterg_sh_user_jid` (`server_host`, `username`(75), `jid`(75));
                ALTER TABLE `muc_room` ADD COLUMN `server_host` VARCHAR (191) COLLATE `utf8mb4_unicode_ci` NOT NULL DEFAULT @DEFAULT_HOST AFTER `host`;
                ALTER TABLE `muc_room` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `spool` DROP INDEX `i_despool`;
                ALTER TABLE `spool` ADD COLUMN `server_host` VARCHAR (191) COLLATE `utf8mb4_unicode_ci` NOT NULL DEFAULT @DEFAULT_HOST AFTER `username`;
                ALTER TABLE `spool` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `spool` ADD INDEX `i_spool_sh_username` USING BTREE (`server_host`, `username`);
                ALTER TABLE `archive` DROP INDEX `i_username_timestamp`;
                ALTER TABLE `archive` DROP INDEX `i_username_peer`;
                ALTER TABLE `archive` DROP INDEX `i_username_bare_peer`;
                ALTER TABLE `archive` DROP INDEX `i_timestamp`;
                ALTER TABLE `archive` ADD COLUMN `server_host` VARCHAR (191) COLLATE `utf8mb4_unicode_ci` NOT NULL DEFAULT @DEFAULT_HOST AFTER `username`;
                ALTER TABLE `archive` ALTER COLUMN `server_host` DROP DEFAULT;
                ALTER TABLE `archive` ADD INDEX `i_archive_sh_username_bare_peer` USING BTREE (`server_host`, `username`, `bare_peer`);
                ALTER TABLE `archive` ADD INDEX `i_archive_sh_timestamp` USING BTREE (`server_host`, `timestamp`);
                ALTER TABLE `archive` ADD INDEX `i_archive_sh_username_timestamp` USING BTREE (`server_host`, `username`, `timestamp`);
                ALTER TABLE `archive` ADD INDEX `i_archive_sh_username_peer` USING BTREE (`server_host`, `username`, `peer`);
        END IF;
        SET FOREIGN_KEY_CHECKS = 1;
END;
##
DELIMITER ;

CALL update_server_host(@DEFAULT_HOST);

DROP PROCEDURE update_server_host;

COMMIT;