-
Notifications
You must be signed in to change notification settings - Fork 1
/
schema.sql
86 lines (77 loc) · 2.61 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
CREATE DATABASE IF NOT EXISTS readme
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE UTF8_GENERAL_CI;
USE readme;
CREATE TABLE IF NOT EXISTS users (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
dt_add TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
email VARCHAR(128) NOT NULL UNIQUE,
name VARCHAR(32) NOT NULL UNIQUE,
password VARCHAR(64) NOT NULL,
avatar_path VARCHAR(128)
);
CREATE TABLE IF NOT EXISTS categories (
id TINYINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(64) NOT NULL,
icon_class VARCHAR(128) NOT NULL
);
CREATE TABLE IF NOT EXISTS posts (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
dt_add TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
title VARCHAR(128) NOT NULL,
description TEXT,
quote_author VARCHAR(128) DEFAULT 'Неизвестный автор',
img_path VARCHAR(128),
video_path VARCHAR(128),
site_link VARCHAR(128),
show_count INT,
repost TINYINT(1) UNSIGNED NOT NULL default 0,
user_id INT UNSIGNED NOT NULL,
category_id TINYINT UNSIGNED NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (category_id) REFERENCES categories(id)
);
CREATE TABLE IF NOT EXISTS comments (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
dt_add TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
description TEXT NOT NULL,
user_id INT UNSIGNED NOT NULL,
post_id INT UNSIGNED NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (post_id) REFERENCES posts(id)
);
CREATE TABLE IF NOT EXISTS likes (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
dt_add TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
user_id INT UNSIGNED NOT NULL,
post_id INT UNSIGNED NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (post_id) REFERENCES posts(id)
);
CREATE TABLE IF NOT EXISTS subscriptions (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
author_id INT UNSIGNED NOT NULL,
follower_id INT UNSIGNED NOT NULL,
FOREIGN KEY (author_id) REFERENCES users(id),
FOREIGN KEY (follower_id) REFERENCES users(id)
);
CREATE TABLE IF NOT EXISTS messages (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
dt_add TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
description TEXT NOT NULL,
sender_id INT UNSIGNED NOT NULL,
recipient_id INT UNSIGNED NOT NULL,
FOREIGN KEY (sender_id) REFERENCES users(id),
FOREIGN KEY (recipient_id) REFERENCES users(id)
);
CREATE TABLE IF NOT EXISTS tags (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(32) NOT NULL UNIQUE
);
CREATE TABLE IF NOT EXISTS trends (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
post_id INT UNSIGNED NOT NULL,
tag_id INT UNSIGNED NOT NULL,
FOREIGN KEY (post_id) REFERENCES posts(id),
FOREIGN KEY (tag_id) REFERENCES tags(id)
);