-
Notifications
You must be signed in to change notification settings - Fork 1
/
schema.sql
42 lines (38 loc) · 1.17 KB
/
schema.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
CREATE TABLE categories(
id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
name varchar(255) NOT NULL
);
CREATE TABLE users(
id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
email varchar(255) UNIQUE NOT NULL,
password_hash varchar(255) NOT NULL,
first_name varchar(255) NOT NULL,
last_name varchar(255) NOT NULL,
avatar varchar(50) NOT NULL
);
CREATE TABLE posts(
id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
title varchar(255) NOT NULL,
announce text NOT NULL,
fullText text NOT NULL,
picture varchar(50),
user_id integer NOT NULL,
created_at varchar(255) NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE comments(
id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
post_id integer NOT NULL,
user_id integer NOT NULL,
text text NOT NULL,
created_at timestamp DEFAULT current_timestamp,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (post_id) REFERENCES posts(id)
);
CREATE TABLE post_categories(
post_id integer NOT NULL,
category_id integer NOT NULL,
PRIMARY KEY (post_id, category_id),
FOREIGN KEY (post_id) REFERENCES posts(id),
FOREIGN KEY (category_id) REFERENCES categories(id)
);