1

Adding foreign key constraint

This commit is contained in:
Alex Yatskov 2015-03-26 13:32:19 +09:00
parent fddc901332
commit aecaf6a8f8
3 changed files with 10 additions and 5 deletions

1
db/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

View File

@ -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))');
//

View File

@ -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