]> Untitled Git - lemmy.git/blob - migrations/2021-02-14-041356_split_user_table/up.sql
Starting on user_ to person migration.
[lemmy.git] / migrations / 2021-02-14-041356_split_user_table / up.sql
1 -- Drop the 2 views user_alias_1, user_alias_2
2 drop view user_alias_1, user_alias_2;
3
4 -- rename the user_ table to person
5 alter table user_ rename to person;
6
7 -- create a new table local_user
8 create table local_user (
9   id serial primary key,
10   user_id int references person on update cascade on delete cascade not null,
11   password_encrypted text not null,
12   email text,
13   admin boolean default false not null,
14   show_nsfw boolean default false not null,
15   theme character varying(20) default 'darkly'::character varying not null,
16   default_sort_type smallint default 0 not null,
17   default_listing_type smallint default 1 not null,
18   lang character varying(20) default 'browser'::character varying not null,
19   show_avatars boolean default true not null,
20   send_notifications_to_email boolean default false not null,
21   matrix_user_id text,
22   unique (user_id)
23 );
24
25 -- Copy the local users over to the new table
26 insert into local_user 
27 (
28   user_id,
29   password_encrypted,
30   email,
31   admin,
32   show_nsfw,
33   theme,
34   default_sort_type,
35   default_listing_type,
36   lang,
37   show_avatars,
38   send_notifications_to_email,
39   matrix_user_id
40 )
41 select
42   id,
43   password_encrypted,
44   email,
45   admin,
46   show_nsfw,
47   theme,
48   default_sort_type,
49   default_listing_type,
50   lang,
51   show_avatars,
52   send_notifications_to_email,
53   matrix_user_id
54 from person
55 where local = true;
56
57 -- Drop those columns from person
58 alter table person 
59   drop column password_encrypted,
60   drop column email,
61   drop column admin,
62   drop column show_nsfw,
63   drop column theme,
64   drop column default_sort_type,
65   drop column default_listing_type,
66   drop column lang,
67   drop column show_avatars,
68   drop column send_notifications_to_email,
69   drop column matrix_user_id;
70
71 -- Rename indexes
72 alter index user__pkey rename to person__pkey;
73 alter index idx_user_actor_id rename to idx_person_actor_id;
74 alter index idx_user_inbox_url rename to idx_person_inbox_url;
75 alter index idx_user_lower_actor_id rename to idx_person_lower_actor_id;
76 alter index idx_user_published rename to idx_person_published;
77
78 -- Rename triggers
79 alter trigger site_aggregates_user_delete on person rename to site_aggregates_person_delete;
80 alter trigger site_aggregates_user_insert on person rename to site_aggregates_person_insert;
81 alter trigger user_aggregates_user on person rename to person_aggregates_person;
82
83 -- Rename the trigger functions
84 alter function site_aggregates_user_delete() rename to site_aggregates_person_delete;
85 alter function site_aggregates_user_insert() rename to site_aggregates_person_insert;
86 alter function user_aggregates_user() rename to person_aggregates_person;
87
88 -- Create views
89 create view person_alias_1 as select * from person;
90 create view person_alias_2 as select * from person;
91
92 -- Rename every user_id column to person_id
93