]> Untitled Git - lemmy.git/blob - migrations/2021-04-02-021422_remove_community_creator/down.sql
Add legal information (fixes #721) (#2273)
[lemmy.git] / migrations / 2021-04-02-021422_remove_community_creator / down.sql
1
2 --  Add the column back
3 alter table community 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 community
10 set creator_id = sub.person_id
11 from (
12   select 
13   cm.community_id,
14   cm.person_id
15   from 
16   community_moderator cm
17   limit 1
18 ) as sub
19 where id = sub.community_id;
20
21 -- Set to not null
22 alter table community alter column creator_id set not null;
23
24