File tree 1 file changed +29
-0
lines changed 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ -- query to identify the duplicate rows in bulk_message_user_refs table
3
+ SELECT count (* ), bulk_message_id, user_id FROM " bulk_message_user_refs"
4
+ GROUP BY bulk_message_id, user_id HAVING count (* ) > 1 ;
5
+
6
+ -- create temp table and store duplicate broadcast notification rows
7
+ SELECT * INTO temptable FROM " Notifications" WHERE id IN
8
+ (
9
+ SELECT a .notification_id FROM " bulk_message_user_refs" AS " a" ,
10
+ " bulk_message_user_refs" AS " b"
11
+ WHERE a .id < b .id
12
+ AND a .bulk_message_id = b .bulk_message_id
13
+ AND a .user_id = b .user_id
14
+ );
15
+
16
+ -- DELETE duplicate rows from bulk_message_user_refs table
17
+ DELETE FROM " bulk_message_user_refs" AS " a"
18
+ USING " bulk_message_user_refs" AS " b"
19
+ WHERE a .id < b .id
20
+ AND a .bulk_message_id = b .bulk_message_id
21
+ AND a .user_id = b .user_id ;
22
+
23
+ -- DELETE duplicate rows from Notifications
24
+ DELETE FROM " Notifications"
25
+ WHERE id IN (SELECT id FROM temptable)
26
+ AND type = ' admin.notification.broadcast' ;
27
+
28
+ -- make unique column to avoid duplicate insert
29
+ ALTER TABLE bulk_message_user_refs ADD UNIQUE (bulk_message_id, user_id);
You can’t perform that action at this time.
0 commit comments