· 10 years ago · Sep 25, 2016, 10:02 AM
1CREATE TABLE IF NOT EXISTS `articles` (
2 `articleID` int(11) NOT NULL AUTO_INCREMENT,
3 `userID` int(11) NOT NULL,
4 `title` varchar(30) NOT NULL,
5 `body` text NOT NULL,
6 `createdAt` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
7 PRIMARY KEY (`articleID`),
8 KEY `fk_articles_user` (`userID`),
9 CONSTRAINT `fk_articles_user` FOREIGN KEY (`userID`) REFERENCES `users` (`userID`) ON DELETE CASCADE
10);
11
12INSERT INTO `articles` (`articleID`, `userID`, `title`, `body`, `createdAt`) VALUES
13 (1, 1, 'Best Article Ever', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed id congue tellus. Pellentesque mollis erat quis dapibus maximus. Integer interdum, leo eu pulvinar accumsan, lorem mi feugiat justo, nec pharetra ante ante at sapien. Fusce varius a eros vitae venenatis. Ut ultricies laoreet volutpat.', '2016-09-25 03:35:23'),
14 (2, 2, 'phasellus aliquam nisl', 'Quisque quis lorem pretium, hendrerit ligula non, blandit dolor. Pellentesque tincidunt sapien ex, id laoreet velit placerat vel. Suspendisse potenti. Phasellus aliquam nisl quis pharetra feugiat.', '2016-09-25 03:35:25');
15
16CREATE TABLE IF NOT EXISTS `comments` (
17 `commentID` int(11) NOT NULL AUTO_INCREMENT,
18 `userID` int(11) NOT NULL,
19 `articleID` int(11) NOT NULL,
20 `body` text NOT NULL,
21 `parentID` int(11) DEFAULT NULL,
22 `createdAt` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
23 PRIMARY KEY (`commentID`),
24 KEY `fk_comments_users` (`userID`),
25 KEY `fk_comments_articles` (`articleID`),
26 KEY `fk_comments_comments` (`parentID`),
27 CONSTRAINT `fk_comments_articles` FOREIGN KEY (`articleID`) REFERENCES `articles` (`articleID`) ON DELETE CASCADE,
28 CONSTRAINT `fk_comments_comments` FOREIGN KEY (`parentID`) REFERENCES `comments` (`commentID`) ON DELETE CASCADE,
29 CONSTRAINT `fk_comments_users` FOREIGN KEY (`userID`) REFERENCES `users` (`userID`) ON DELETE CASCADE
30);
31
32INSERT INTO `comments` (`commentID`, `userID`, `articleID`, `body`, `parentID`, `createdAt`) VALUES
33 (1, 2, 1, 'That is extremely interesting!', NULL, '2016-09-25 03:36:52'),
34 (3, 1, 2, 'And you call my article uninteresting!', NULL, '2016-09-25 03:36:52'),
35 (4, 2, 2, 'Y u mad tho?', 3, '2016-09-25 03:36:52');
36
37CREATE TABLE IF NOT EXISTS `users` (
38 `userID` int(11) NOT NULL AUTO_INCREMENT,
39 `username` varchar(30) NOT NULL,
40 `password` varchar(60) NOT NULL,
41 `otherID` varchar(20) DEFAULT NULL,
42 `access_token` tinytext,
43 PRIMARY KEY (`userID`)
44);
45
46INSERT INTO `users` (`userID`, `username`, `password`, `otherID`, `access_token`) VALUES
47 (1, 'Billytim Cricketwillow', 'asdf1234', '', ''),
48 (2, 'Lou Beasley', '1234asdf', '', ''),
49 (4, 'ktynfowler@gmail.com', '$2a$10$1VY.k7EeZQ8YT7XtyqUuhORl4Y4v/f93ckK2q5Lp.JBKOBL2cm9cu', '1288888654457423', 'EAAZAQjhelLh8BADFtcjNDPlEEmmMuYtrJL9SuebL16Ah6HtNUoo6LT4WVeY7qX8XjQd1HmTgh8t4fjTqYfZAeJ9ZADIf7DFvglFkH8uUU3jXuJMHmZC5kXGZAH2JHu6KwjJrsim8Kmv4cX1iA9I7UAnjx0ZCYC4TIO33zyaIk9ZAwZDZD');