forked from harimau97/UhPooh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uhpooh.sql
80 lines (74 loc) · 2.58 KB
/
uhpooh.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
-- Create and select database
DROP DATABASE IF EXISTS uhpooh;
CREATE SCHEMA IF NOT EXISTS `uhpooh` DEFAULT
CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci ;
USE uhpooh;
-- Users table
CREATE TABLE users (
userId INT AUTO_INCREMENT PRIMARY KEY,
userEmail VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255),
userName VARCHAR(50) NOT NULL,
pImage VARCHAR(255),
isAdmin BOOLEAN DEFAULT FALSE,
regTime DATETIME DEFAULT CURRENT_TIMESTAMP,
updTime DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
isLogin BOOLEAN DEFAULT TRUE
);
-- Token table
CREATE TABLE token (
id INTEGER NOT NULL AUTO_INCREMENT,
is_logged_out BIT,
userId INTEGER,
accessToken VARCHAR(255),
refreshToken VARCHAR(255),
PRIMARY KEY (id),
FOREIGN KEY (userId) REFERENCES users(userId)
) ENGINE=InnoDB;
-- Places table
CREATE TABLE places (
placeId INT AUTO_INCREMENT PRIMARY KEY,
kakaoPlaceId VARCHAR(100) NOT NULL UNIQUE,
reviewCount INT DEFAULT 0,
likeCount INT DEFAULT 0,
regTime DATETIME DEFAULT CURRENT_TIMESTAMP,
updTime DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idxKakaoPlaceId (kakaoPlaceId)
);
-- Reviews table
CREATE TABLE reviews (
reviewId INT AUTO_INCREMENT PRIMARY KEY,
userId INT NOT NULL,
placeId INT NOT NULL,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL,
images VARCHAR(255),
regTime DATETIME DEFAULT CURRENT_TIMESTAMP,
updTime DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (userId) REFERENCES users(userId) ON DELETE CASCADE,
FOREIGN KEY (placeId) REFERENCES places(placeId) ON DELETE CASCADE,
INDEX idxUserPlace (userId, placeId)
);
-- Likes table
CREATE TABLE likes (
likeId INT AUTO_INCREMENT PRIMARY KEY,
userId INT NOT NULL,
placeId INT NOT NULL,
regTime DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (userId) REFERENCES users(userId) ON DELETE CASCADE,
FOREIGN KEY (placeId) REFERENCES places(placeId) ON DELETE CASCADE,
UNIQUE KEY uniqueUserPlace (userId, placeId)
);
-- Payments table
CREATE TABLE payments (
paymentId INT AUTO_INCREMENT PRIMARY KEY,
userId INT NOT NULL,
tossPaymentKey VARCHAR(200) NOT NULL,
amount INT NOT NULL,
status ENUM('READY', 'IN_PROGRESS', 'DONE', 'CANCELED', 'FAILED') DEFAULT 'READY',
regTime DATETIME DEFAULT CURRENT_TIMESTAMP,
updTime DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (userId) REFERENCES users(userId) ON DELETE CASCADE,
INDEX idxOrderId (paymentId),
INDEX idxPaymentKey (tossPaymentKey)
);