From 4dbfff5cd13681dd9dcc06010d8c4072ce934952 Mon Sep 17 00:00:00 2001 From: Jon Bonilla Date: Mon, 3 Sep 2012 07:53:13 +0000 Subject: [PATCH] Finally remove ossbss peer_rules duplicates too It was possible to add same rule to same group via ossbss. --- db_scripts/diff/10180.up | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/db_scripts/diff/10180.up b/db_scripts/diff/10180.up index 8d6fbe15..677b9b8a 100644 --- a/db_scripts/diff/10180.up +++ b/db_scripts/diff/10180.up @@ -1,8 +1,22 @@ # Remove duplicated rules on the same group. Triggers should do the rest for lcr_rule. use provisioning; -ALTER IGNORE TABLE voip_peer_rules ADD UNIQUE KEY `idx1temp` (`group_id`, `callee_prefix`, `callee_pattern`, `caller_pattern`); -ALTER TABLE voip_peer_rules DROP KEY `idx1temp`; +#make sure that the repeated have caller_prefix '' instead of null or won't be detected +UPDATE voip_peer_rules SET caller_pattern='' WHERE caller_pattern IS NULL; + +#Can't use ALTER IGNORE in Percona https://bugs.launchpad.net/percona-xtradb/+bug/604439 +#ALTER IGNORE TABLE voip_peer_rules ADD UNIQUE KEY `idx1temp` (`group_id`, `callee_prefix`, `callee_pattern`, `caller_pattern`); +#ALTER TABLE voip_peer_rules DROP KEY `idx1temp`; + + +#Remove duplicated that could be added via ossbss. Removed keys via triggers will be added later +CREATE TABLE newtemp LIKE voip_peer_rules; +ALTER TABLE newtemp ADD UNIQUE KEY `idx1temp` (`group_id`, `callee_prefix`, `callee_pattern`, `caller_pattern`); +INSERT IGNORE INTO newtemp SELECT * FROM voip_peer_rules; +DELETE FROM voip_peer_rules; +INSERT INTO voip_peer_rules SELECT * FROM newtemp; +DROP table newtemp; + # Now we can create the unique key without duplicates use kamailio;