create_db.sql
1.15 KB
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
CREATE DATABASE mamuri_db;
USE mamuri_db;
CREATE TABLE user
(
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL
);
CREATE TABLE keyword
(
id INT AUTO_INCREMENT PRIMARY KEY,
keyword VARCHAR(150) NULL
);
CREATE TABLE user_keyword
(
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
keyword_id INT NOT NULL,
FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE,
FOREIGN KEY (keyword_id) REFERENCES keyword (id) ON DELETE CASCADE
);
CREATE TABLE item
(
id INT AUTO_INCREMENT PRIMARY KEY,
keyword_id INT NOT NULL,
platform VARCHAR(50) NOT NULL,
name VARCHAR(100) NOT NULL,
price INT NOT NULL,
thumbnail_url VARCHAR(255) NULL,
item_url VARCHAR(255) NOT NULL,
extra_info TEXT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE item_check
(
id INT AUTO_INCREMENT PRIMARY KEY,
item_id INT NULL,
user_id INT NULL,
FOREIGN KEY (item_id) REFERENCES item (id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE
);