-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnode_blogs.sql
More file actions
38 lines (32 loc) · 1.29 KB
/
node_blogs.sql
File metadata and controls
38 lines (32 loc) · 1.29 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
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`);