我需要将聊天对话存储在数据库模式中。我使用这个数据库的方式是在网站上发布聊天记录。每个聊天不会超过大约 20 个响应。有人可以为此建议一个架构吗?
问问题
89287 次
2 回答
35
和创建脚本
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';
CREATE SCHEMA IF NOT EXISTS `chats` DEFAULT CHARACTER SET utf8 COLLATE default collation ;
-- -----------------------------------------------------
-- Table `chats`.`chat`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `chats`.`chat` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
PRIMARY KEY (`id`) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `chats`.`chat_user`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `chats`.`chat_user` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`handle` VARCHAR(45) NOT NULL ,
PRIMARY KEY (`id`) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `chats`.`chat_line`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `chats`.`chat_line` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT ,
`chat_id` INT UNSIGNED NOT NULL ,
`user_id` INT UNSIGNED NOT NULL ,
`line_text` TEXT NOT NULL ,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
PRIMARY KEY (`id`) ,
INDEX `fk_chat_line_chat` (`chat_id` ASC) ,
INDEX `fk_chat_line_chat_user1` (`user_id` ASC) ,
CONSTRAINT `fk_chat_line_chat`
FOREIGN KEY (`chat_id` )
REFERENCES `chats`.`chat` (`id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_chat_line_chat_user1`
FOREIGN KEY (`user_id` )
REFERENCES `chats`.`chat_user` (`id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
欢迎您从我的保管箱下载 MWB 文件。
于 2010-06-22T16:08:29.253 回答
5
对话 has_may 台词
Line belongs_to User,有内容和时间
于 2010-06-22T15:16:13.657 回答