]> Untitled Git - lemmy.git/blob - migrations/2021-11-22-135324_add_activity_ap_id_index/up.sql
Fix API dupes query. #1878
[lemmy.git] / migrations / 2021-11-22-135324_add_activity_ap_id_index / up.sql
1
2 -- Delete the empty ap_ids
3 delete from activity where ap_id is null;
4
5 -- Make it required
6 alter table activity alter column ap_id set not null;
7
8 -- Delete dupes, keeping the first one
9 delete from activity a using (
10   select min(id) as id, ap_id
11   from activity
12   group by ap_id having count(*) > 1
13 ) b
14 where a.ap_id = b.ap_id 
15 and a.id <> b.id;
16
17 -- The index
18 create unique index idx_activity_ap_id on activity(ap_id);
19
20 -- Drop the old index
21 drop index idx_activity_unique_apid;
22