]> Untitled Git - lemmy.git/blob - migrations/2023-07-11-084714_receive_activity_table/up.sql
Fixing broken SQL migration formatting. (#3800)
[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
22     ap_id,
23     data,
24     sensitive,
25     published
26 FROM
27     activity
28 WHERE
29     local = TRUE
30 ORDER BY
31     id DESC
32 LIMIT 100000;
33
34 -- copy received activities to new table. only last 1m for faster migration
35 INSERT INTO received_activity (ap_id, published)
36 SELECT
37     ap_id,
38     published
39 FROM
40     activity
41 WHERE
42     local = FALSE
43 ORDER BY
44     id DESC
45 LIMIT 1000000;
46
47 DROP TABLE activity;
48