Skip to content

Commit

Permalink
Merge pull request #59 from osamhack2022/backend-feat-image
Browse files Browse the repository at this point in the history
Backend feat image
  • Loading branch information
Turtle-Hwan authored Oct 15, 2022
2 parents 6d806c7 + 7f57075 commit 66acdbd
Show file tree
Hide file tree
Showing 8 changed files with 426 additions and 744 deletions.
97 changes: 41 additions & 56 deletions backend/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,51 @@ drop database IF EXISTS milidream_db;
create database milidream_db;
use milidream_db;

create table Class(
classKey INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
classType TEXT /*CHARACTER SET utf8mb4*/ NOT NULL
);

create table User (
userKey INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
userName VARCHAR(20) UNIQUE KEY NOT NULL,
id VARCHAR(20) UNIQUE KEY NOT NULL,
passwd VARCHAR(64) NOT NULL,
classKey INT NOT NULL,
FOREIGN KEY(classKey) REFERENCES Class(classKey) ON UPDATE RESTRICT ON DELETE CASCADE
);

create table Category(
categoryKey INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
categoryName TEXT NOT NULL
);

create table Post (
postKey INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
userKey INT NOT NULL,
postTime DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
title TEXT NOT NULL,
body TEXT NOT NULL,
categoryKey INT NOT NULL,
viewCount INT NOT NULL DEFAULT 0,
FOREIGN KEY(categoryKey) REFERENCES Category(categoryKey) ON UPDATE RESTRICT ON DELETE CASCADE
);

create table CareerPost(
careerPostKey INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
competitionKey INT NOT NULL,
recruitKey INT NOT NULL,
FOREIGN KEY(competitionKey) REFERENCES Post(postKey) ON UPDATE RESTRICT ON DELETE CASCADE,
FOREIGN KEY(recruitKey) REFERENCES Post(postKey) ON UPDATE RESTRICT ON DELETE CASCADE
);

create table Recommenders(
recommenderKey INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
postKey INT NOT NULL,
userKey INT NOT NULL,
FOREIGN KEY(postKey) REFERENCES Post(postKey) ON UPDATE RESTRICT ON DELETE CASCADE,
FOREIGN KEY(userKey) REFERENCES User(userKey) ON UPDATE RESTRICT ON DELETE CASCADE
);

create table Comment(
commentKey INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
userKey INT NOT NULL,
body TEXT NOT NULL,
postKey INT NOT NULL,
commentTime DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
parentKey INT,
FOREIGN KEY(userKey) REFERENCES User(userKey) ON UPDATE RESTRICT ON DELETE SET NULL,
FOREIGN KEY(postKey) REFERENCES Post(postKey) ON UPDATE RESTRICT ON DELETE CASCADE
);

create table Class(classKey INT AUTO_INCREMENT PRIMARY KEY,
classContent TEXT /*CHARACTER SET utf8mb4*/ NOT NULL);

create table User (userKey INT AUTO_INCREMENT PRIMARY KEY,
userName VARCHAR(20) UNIQUE KEY NOT NULL,
id VARCHAR(20) UNIQUE KEY NOT NULL,
passwd VARCHAR(64) NOT NULL,
imgUrl VARCHAR(200),
classKey INT NOT NULL,
FOREIGN KEY(classKey) REFERENCES Class(classKey));

create table Category(categoryKey INT AUTO_INCREMENT PRIMARY KEY, categoryName TEXT NOT NULL);

create table Post (postKey INT AUTO_INCREMENT PRIMARY KEY,
userkey INT NOT NULL,
postTime DATETIME DEFAULT CURRENT_TIMESTAMP,
title TEXT NOT NULL,
body TEXT NOT NULL,
imgUrl VARCHAR(200),
categoryKey INT NOT NULL,
careerPostKey INT,
FOREIGN KEY(categoryKey) REFERENCES Category(categoryKey),
FOREIGN KEY(careerPostKey) REFERENCES Post(postKey));

create table Comment(commentKey INT AUTO_INCREMENT PRIMARY KEY,
userKey INT NOT NULL,
content TEXT NOT NULL,
postKey INT NOT NULL,
commentTime DATETIME DEFAULT CURRENT_TIMESTAMP,
parentKey INT,
FOREIGN KEY(userKey) REFERENCES User(userKey),
FOREIGN KEY(postKey) REFERENCES Post(postKey),
FOREIGN KEY(parentKey) REFERENCES Comment(commentKey));

create table MBTI(mbtiKEY INT AUTO_INCREMENT PRIMARY KEY,
mbtiType TEXT NOT NULL,
mbtiContent TEXT NOT NULL);



-- FOREIGN KEY(parentKey) REFERENCES Comment(commentKey) ON UPDATE RESTRICT ON DELETE CASCADE

insert into Class (classType) values ("미정"), ("병사"), ("간부"), ("군무원");

select * from Class;
insert into User (userName, id, passwd, classKey) values ("username1", "userid1", "1b072274a5bb6d2b1bf1948bad724a13ca2ad51eef2bce42ebb8a1d640cffaaa", 1), -- userpassword1
("username2", "userid2", "4917c2a60a2d898906e16e61c602c4cbccae42b1f89d2da9f6e523031d0d5b3b", 2); -- userpassword2@
Expand Down
Loading

0 comments on commit 66acdbd

Please sign in to comment.