mirror of https://github.com/sipwise/db-schema.git
also suffix already existing duplicates with CONCAT("-", voip_subscriber.id).2.6
parent
4b6e9c0e28
commit
ab1dabecfb
@ -0,0 +1,11 @@
|
|||||||
|
USE provisioning;
|
||||||
|
|
||||||
|
DELETE FROM language_strings WHERE code='Client.Voip.ExistingWebUser';
|
||||||
|
|
||||||
|
-- delete unique constraint
|
||||||
|
ALTER TABLE voip_subscribers DROP INDEX webuser_dom_idx;
|
||||||
|
|
||||||
|
-- remove suffix set when adding above unique constraint
|
||||||
|
UPDATE voip_subscribers
|
||||||
|
SET webusername=REPLACE(webusername, CONCAT('-', id), '')
|
||||||
|
WHERE webusername LIKE CONCAT('%', '-', id)
|
@ -0,0 +1,23 @@
|
|||||||
|
USE provisioning;
|
||||||
|
|
||||||
|
INSERT INTO language_strings (code, language, string) VALUES ('Client.Voip.ExistingWebUser', 'en', 'This webuser is already in use.');
|
||||||
|
INSERT INTO language_strings (code, language, string) VALUES ('Client.Voip.ExistingWebUser', 'de', 'Dieser Webuser ist nicht mehr verfügbar.');
|
||||||
|
INSERT INTO language_strings (code, language, string) VALUES ('Client.Voip.ExistingWebUser', 'es', 'This webuser is already in use.');
|
||||||
|
INSERT INTO language_strings (code, language, string) VALUES ('Client.Voip.ExistingWebUser', 'fr', 'This webuser is already in use.');
|
||||||
|
|
||||||
|
-- need to check if there are duplicates in voip_subscribers.webusername and
|
||||||
|
-- suffix them with with "-"voip_subscribers.id before createing unique constraint (see below)
|
||||||
|
CREATE OR REPLACE VIEW webusername_dupes_view
|
||||||
|
AS select webusername, count(*) c from voip_subscribers group by webusername having c > 1;
|
||||||
|
|
||||||
|
UPDATE voip_subscribers
|
||||||
|
SET voip_subscribers.webusername = CONCAT(voip_subscribers.webusername, '-', voip_subscribers.id)
|
||||||
|
WHERE
|
||||||
|
voip_subscribers.webusername IN (
|
||||||
|
SELECT webusername FROM webusername_dupes_view
|
||||||
|
);
|
||||||
|
|
||||||
|
DROP VIEW webusername_dupes_view;
|
||||||
|
|
||||||
|
-- its safe now to make voip_subscribers.webusername unique
|
||||||
|
ALTER TABLE voip_subscribers ADD CONSTRAINT UNIQUE KEY `webuser_dom_idx` (`webusername`,`domain_id`);
|
Loading…
Reference in new issue