2 -- Delete the empty ap_ids
3 delete from activity where ap_id is null;
6 alter table activity alter column ap_id set not null;
8 -- Delete dupes, keeping the first one
9 delete from activity a using (
10 select min(id) as id, ap_id
12 group by ap_id having count(*) > 1
14 where a.ap_id = b.ap_id
18 create unique index idx_activity_ap_id on activity(ap_id);
21 drop index idx_activity_unique_apid;