express middleware, next()
settimeout함수 sleep
$ touch server.js
$ npm init -y
$ npm i express sequelize sequelize-cli mysql2
$ npm i -D nodemon (D=>stands for dependencies (바로바로 저장되고 바로실행된다.))
$ npx sequelize init (Don't need migration and seeders)
DROP TABLE IF EXISTS users, articles, comments;
CREATE TABLE `users` (
`id` int PRIMARY KEY AUTO_INCREMENT,
`email` varchar(100) UNIQUE NOT NULL,
`password` varchar(200) NOT NULL,
`status` ENUM ('ACTIVE', 'INACTIVE') NOT NULL DEFAULT "ACTIVE",
`created_at` datetime DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime ON UPDATE CURRENT_TIMESTAMP, # 수정된 부분
`deleted_at` datetime DEFAULT null
);
CREATE TABLE `articles` (
`id` int PRIMARY KEY AUTO_INCREMENT,
`user_id` int NOT NULL,
`title` varchar(200) NOT NULL,
`body` varchar(2000) NOT NULL,
`status` ENUM ('DRAFT', 'PUBLISHED', 'DELETED') NOT NULL DEFAULT "DRAFT",
`created_at` datetime DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime ON UPDATE CURRENT_TIMESTAMP,
`deleted_at` datetime DEFAULT null
);
CREATE TABLE `comments` (
`id` int PRIMARY KEY AUTO_INCREMENT,
`article_id` int NOT NULL,
`user_id` int NOT NULL,
`body` varchar(1000) NOT NULL,
`created_at` datetime DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime ON UPDATE CURRENT_TIMESTAMP,
`deleted_at` datetime DEFAULT null
);
# 외래키 설정하는 부분
ALTER TABLE `articles` ADD FOREIGN KEY (`user_id`) REFERENCES `users` (`id`);
ALTER TABLE `comments` ADD FOREIGN KEY (`article_id`) REFERENCES `articles` (`id`);
ALTER TABLE `comments` ADD FOREIGN KEY (`user_id`) REFERENCES `users` (`id`);
3.ERD이름.sql 파일을 MySQL 데이터베이스에 마이그레이션 하기