]> Untitled Git - lemmy.git/blob - migrations/2023-07-11-084714_receive_activity_table/up.sql
Split activity table into sent and received parts (fixes #3103) (#3583)
[lemmy.git] / migrations / 2023-07-11-084714_receive_activity_table / up.sql
1 -- outgoing activities, need to be stored to be later server over http
2 -- we change data column from jsonb to json for decreased size
3 -- https://stackoverflow.com/a/22910602
4 create table sent_activity (
5     id bigserial primary key,
6     ap_id text unique not null,
7     data json not null,
8     sensitive boolean not null,
9     published timestamp not null default now()
10 );
11
12 -- incoming activities, we only need the id to avoid processing the same activity multiple times
13 create table received_activity (
14     id bigserial primary key,
15     ap_id text unique not null,
16     published timestamp not null default now()
17 );
18
19 -- copy sent activities to new table. only copy last 100k for faster migration
20 insert into sent_activity(ap_id, data, sensitive, published)
21     select ap_id, data, sensitive, published
22     from activity
23     where local = true
24     order by id desc
25     limit 100000;
26
27 -- copy received activities to new table. only last 1m for faster migration
28 insert into received_activity(ap_id, published)
29     select ap_id, published
30     from activity
31     where local = false
32     order by id desc
33     limit 1000000;
34
35 drop table activity;