-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLesson3_vk.sql
72 lines (62 loc) · 1.84 KB
/
Lesson3_vk.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
CREATE DATABASE vk;
USE vk;
CREATE TABLE users (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL,
email VARCHAR(150) NOT NULL UNIQUE,
phone VARCHAR(30) NOT NULL UNIQUE,
created_at DATETIME DEFAULT NOW(),
updated_at DATETIME DEFAULT NOW() ON UPDATE NOW()
);
CREATE TABLE profiles (
user_id INT UNSIGNED NOT NULL PRIMARY KEY,
sex CHAR(1) NOT NULL,
birthday DATE,
hometown VARCHAR(100),
photo_id INT UNSIGNED NOT NULL
);
CREATE TABLE messages (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
from_user_id INT UNSIGNED NOT NULL,
to_user_id INT UNSIGNED NOT NULL,
body TEXT NOT NULL,
is_important BOOLEAN,
is_delivered BOOLEAN,
created_at DATETIME DEFAULT NOW()
);
CREATE TABLE friendship (
user_id INT UNSIGNED NOT NULL,
friend_id INT UNSIGNED NOT NULL,
status_id INT UNSIGNED NOT NULL,
requested_at DATETIME DEFAULT NOW(),
confirmed_at DATETIME,
PRIMARY KEY (user_id, friend_id)
);
CREATE TABLE friendship_statuses (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(150) NOT NULL UNIQUE
);
CREATE TABLE communities (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(150) NOT NULL UNIQUE
);
CREATE TABLE communities_users (
community_id INT UNSIGNED NOT NULL,
user_id INT UNSIGNED NOT NULL,
PRIMARY KEY (community_id, user_id)
);
CREATE TABLE media (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
media_type_id INT UNSIGNED NOT NULL,
user_id INT UNSIGNED NOT NULL,
filename VARCHAR(255) NOT NULL,
size INT NOT NULL,
metadata JSON,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
CREATE TABLE media_types (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL UNIQUE
);