]> Untitled Git - lemmy.git/blob - migrations/2021-04-02-021422_remove_community_creator/down.sql
Revert "Attempt to fix CI building wrong commits (#3830)"
[lemmy.git] / migrations / 2021-04-02-021422_remove_community_creator / down.sql
1 --  Add the column back
2 ALTER TABLE community
3     ADD COLUMN creator_id int REFERENCES person ON UPDATE CASCADE ON DELETE CASCADE;
4
5 -- Recreate the index
6 CREATE INDEX idx_community_creator ON community (creator_id);
7
8 -- Add the data, selecting the highest mod
9 UPDATE
10     community
11 SET
12     creator_id = sub.person_id
13 FROM (
14     SELECT
15         cm.community_id,
16         cm.person_id
17     FROM
18         community_moderator cm
19     LIMIT 1) AS sub
20 WHERE
21     id = sub.community_id;
22
23 -- Set to not null
24 ALTER TABLE community
25     ALTER COLUMN creator_id SET NOT NULL;
26