]> Untitled Git - lemmy.git/blob - migrations/2021-11-22-135324_add_activity_ap_id_index/up.sql
Adding unique constraint for activity ap_id. Fixes #1878 (#1935)
[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
10 from activity
11 where id not in (
12   select min(id)
13   from activity
14   group by ap_id
15 );
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