diff --git a/db/.gitignore b/db/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/db/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/db/build_db.js b/db/build_db.js index 232d8c6..1c11451 100755 --- a/db/build_db.js +++ b/db/build_db.js @@ -83,7 +83,7 @@ for (var i = 0, count = categories.length; i < count; ++i) { // conn.query('DROP TABLE IF EXISTS history'); -conn.query('CREATE TABLE history(date DATETIME NOT NULL, reviewId INT NOT NULL, id INT NOT NULL AUTO_INCREMENT PRIMARY KEY)'); +conn.query('CREATE TABLE history(date DATETIME NOT NULL, reviewId INT NOT NULL, id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, FOREIGN KEY(reviewId) REFERENCES reviews(id))'); // @@ -91,7 +91,7 @@ conn.query('CREATE TABLE history(date DATETIME NOT NULL, reviewId INT NOT NULL, // conn.query('DROP TABLE IF EXISTS historyGroups'); -conn.query('CREATE TABLE historyGroups(categoryId INT NOT NULL, categoryValue FLOAT NOT NULL, historyId INT NOT NULL)'); +conn.query('CREATE TABLE historyGroups(categoryId INT NOT NULL, categoryValue FLOAT NOT NULL, historyId INT NOT NULL, FOREIGN KEY(historyId) REFERENCES history(id))'); // diff --git a/db/hscd.sql b/db/hscd.sql index be8fa6a..e7916e4 100644 --- a/db/hscd.sql +++ b/db/hscd.sql @@ -50,7 +50,9 @@ CREATE TABLE `history` ( `date` datetime NOT NULL, `reviewId` int(11) NOT NULL, `id` int(11) NOT NULL AUTO_INCREMENT, - PRIMARY KEY (`id`) + PRIMARY KEY (`id`), + KEY `reviewId` (`reviewId`), + CONSTRAINT `history_ibfk_1` FOREIGN KEY (`reviewId`) REFERENCES `reviews` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; @@ -73,7 +75,9 @@ DROP TABLE IF EXISTS `historyGroups`; CREATE TABLE `historyGroups` ( `categoryId` int(11) NOT NULL, `categoryValue` float NOT NULL, - `historyId` int(11) NOT NULL + `historyId` int(11) NOT NULL, + KEY `historyId` (`historyId`), + CONSTRAINT `historyGroups_ibfk_1` FOREIGN KEY (`historyId`) REFERENCES `history` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; @@ -129,4 +133,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2015-03-17 18:39:51 +-- Dump completed on 2015-03-26 13:31:52