· 6 years ago · Apr 18, 2019, 02:38 PM
1DROP TABLE IF EXISTS security_user;
2DROP TABLE IF EXISTS public.Article cascade;
3DROP TABLE IF EXISTS public.category;
4DROP TABLE IF EXISTS public.comments;
5DROP TABLE IF EXISTS public.news;
6DROP TABLE IF EXISTS public.post;
7DROP TABLE IF EXISTS public.links;
8DROP TABLE IF EXISTS public.account;
9DROP TYPE if exists the_gender;
10CREATE TYPE the_gender AS ENUM ('F', 'M', 'X');
11
12CREATE TABLE IF NOT EXISTS security_user (
13 su_id SERIAL NOT NULL PRIMARY KEY,
14 name VARCHAR(50) UNIQUE ,
15 email varchar(50),
16 password VARCHAR(200),
17 role VARCHAR(50)
18
19);
20
21create table news (
22 id serial not null primary key,
23 id_list_of_comments int,
24 author int,
25 title varchar(100),
26 content text
27
28);
29
30
31create table account (/*author*/
32 id serial not null primary key,
33 security_user_id int unique ,
34 comment_id int,
35 name varchar(50),
36 ip varchar(20),
37 vk varchar(50),
38 gender the_gender,
39 facebook varchar(50),
40 battleTag varchar(50),
41 information text,
42 constraint fk_security_user_id
43 foreign key (security_user_id)
44 references security_user(su_id)
45
46);
47
48create table public.links (
49 id serial not null primary key unique ,
50 tag varchar(250)
51);
52
53create table public.post (
54 id serial not null primary key,
55 images_link_id int,
56 author_id int,
57 title varchar(30),
58 content varchar(100),
59 constraint fk_links
60 foreign key (images_link_id)
61 references links (id),
62 constraint fk_author
63 foreign key (author_id)
64 references account (id)
65
66);
67
68create table public.category (
69 id serial not null primary key,
70 tag varchar(250)
71);
72
73CREATE TABLE public.article (
74 id serial NOT NULL PRIMARY KEY,
75 links_list_id integer,
76 category_id integer,
77 author_name_id int ,
78 title varchar(70),
79 content text,
80 constraint fk_links_list_id
81 foreign key (links_list_id)
82 references links (id),
83 constraint fk_category
84 foreign key (category_id)
85 references category (id)
86);
87
88
89create table comments (
90 id serial not null primary key,
91 author_id int,
92 post_id int,
93 news_id int,
94 article_id int,
95 content text,
96 constraint fk_author
97 foreign key (author_id)
98 references account (id),
99 constraint fk_news
100 foreign key (news_id)
101 references news (id),
102 constraint fk_post
103 foreign key (post_id)
104 references post (id),
105 constraint fk_article
106 FOREIGN KEY (article_id)
107 references article (id)
108
109
110);