]> Untitled Git - lemmy.git/blob - migrations/2019-02-27-170003_create_community/up.sql
add enable_federated_downvotes site option
[lemmy.git] / migrations / 2019-02-27-170003_create_community / up.sql
1 CREATE TABLE category (
2     id serial PRIMARY KEY,
3     name varchar(100) NOT NULL UNIQUE
4 );
5
6 INSERT INTO category (name)
7     VALUES ('Discussion'),
8     ('Humor/Memes'),
9     ('Gaming'),
10     ('Movies'),
11     ('TV'),
12     ('Music'),
13     ('Literature'),
14     ('Comics'),
15     ('Photography'),
16     ('Art'),
17     ('Learning'),
18     ('DIY'),
19     ('Lifestyle'),
20     ('News'),
21     ('Politics'),
22     ('Society'),
23     ('Gender/Identity/Sexuality'),
24     ('Race/Colonisation'),
25     ('Religion'),
26     ('Science/Technology'),
27     ('Programming/Software'),
28     ('Health/Sports/Fitness'),
29     ('Porn'),
30     ('Places'),
31     ('Meta'),
32     ('Other');
33
34 CREATE TABLE community (
35     id serial PRIMARY KEY,
36     name varchar(20) NOT NULL UNIQUE,
37     title varchar(100) NOT NULL,
38     description text,
39     category_id int REFERENCES category ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
40     creator_id int REFERENCES user_ ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
41     removed boolean DEFAULT FALSE NOT NULL,
42     published timestamp NOT NULL DEFAULT now(),
43     updated timestamp
44 );
45
46 CREATE TABLE community_moderator (
47     id serial PRIMARY KEY,
48     community_id int REFERENCES community ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
49     user_id int REFERENCES user_ ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
50     published timestamp NOT NULL DEFAULT now(),
51     UNIQUE (community_id, user_id)
52 );
53
54 CREATE TABLE community_follower (
55     id serial PRIMARY KEY,
56     community_id int REFERENCES community ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
57     user_id int REFERENCES user_ ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
58     published timestamp NOT NULL DEFAULT now(),
59     UNIQUE (community_id, user_id)
60 );
61
62 CREATE TABLE community_user_ban (
63     id serial PRIMARY KEY,
64     community_id int REFERENCES community ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
65     user_id int REFERENCES user_ ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
66     published timestamp NOT NULL DEFAULT now(),
67     UNIQUE (community_id, user_id)
68 );
69
70 INSERT INTO community (name, title, category_id, creator_id)
71     VALUES ('main', 'The Default Community', 1, 1);
72
73 CREATE TABLE site (
74     id serial PRIMARY KEY,
75     name varchar(20) NOT NULL UNIQUE,
76     description text,
77     creator_id int REFERENCES user_ ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
78     published timestamp NOT NULL DEFAULT now(),
79     updated timestamp
80 );
81