 CONSTRAINT `fkGameUserLimit` FOREIGN KEY (`limitOpponentId`) REFERENCES `User` (`id`)
 ) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
 
+-- Stores messages sent in chats.
+-- Messages sent ingame have a game ID and messages sent in the lobby don't.
+CREATE TABLE `ChatMessage` (
+`id` INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT ,
+`message` TEXT NOT NULL ,
+`sentTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
+`senderId` INT UNSIGNED NOT NULL ,
+`gameId` INT UNSIGNED NULL ,
+`system` TINYINT NOT NULL DEFAULT 0 ,
+CONSTRAINT `fkChatMessageUser` FOREIGN KEY (`senderId`) REFERENCES `User`(`id`) ,
+CONSTRAINT `fkChatMessageGame` FOREIGN KEY (`gameId`) REFERENCES `Game`(`id`)
+) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+
 -- CREATE Game / Deck link
 CREATE TABLE GameDeck (
 `gameId` INT UNSIGNED NOT NULL,

`createdOn` DATETIME NOT NULL ,
`startedOn` DATETIME NULL ,
`endedOn` DATETIME NULL ,
`state` LONGTEXT NULL
`running` TINYINT NOT NULL DEFAULT 0 ,
`paused` TINYINT NOT NULL DEFAULT 0 ,
`useGraveyard` TINYINT NOT NULL DEFAULT 1 ,

PRIMARY KEY (`diceId`, `gameId`) ,
CONSTRAINT `fkGameDiceDice` FOREIGN KEY (`diceId`) REFERENCES `Dice`(`id`) ,
CONSTRAINT `fkGameDiceDeck` FOREIGN KEY (`gameId`) REFERENCES `Game`(`id`)
) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_unicode_ci ;