-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.sql
71 lines (61 loc) · 1.76 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
CREATE DATABASE IF NOT EXISTS readme;
USE readme;
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
email VARCHAR(255) UNIQUE NOT NULL,
login VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
name VARCHAR(255)NOT NULL,
avatar VARCHAR(255),
contacts TEXT,
created_at INT(11) NOT NULL
);
CREATE TABLE IF NOT EXISTS type_content (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
class_name VARCHAR(255) NOT NULL
);
CREATE TABLE IF NOT EXISTS posts (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
user_id INTEGER NOT NULL,
type_id INTEGER NOT NULL,
title VARCHAR(255),
text TEXT,
author VARCHAR(255),
photo VARCHAR(255),
video VARCHAR(255),
link VARCHAR(255),
views INT UNSIGNED,
created_at INT(11) NOT NULL
);
CREATE TABLE IF NOT EXISTS comments (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
user_id INTEGER NOT NULL,
post_id INTEGER NOT NULL,
content TEXT
);
CREATE TABLE IF NOT EXISTS likes (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
user_id INTEGER NOT NULL,
post_id INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS subscriptions (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
user_id INTEGER NOT NULL,
whom_id INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS messages (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
user_id INTEGER NOT NULL,
whom_id INTEGER NOT NULL,
content TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS hashtags (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
user_id INTEGER NOT NULL,
post_id INTEGER NOT NULL
);
CREATE INDEX user_created_at ON users(created_at);
CREATE INDEX post_created_at ON posts(created_at);
CREATE INDEX post_user_id ON posts(user_id);
CREATE INDEX comments_post_id ON comments(post_id);