_migration.sql 2.11 KB
/*
    author: feng.chen@yoho.cn
    date: 2017-06-27 11:25:29
    comment: 初始化
*/
#注意:GO;分割执行块

CREATE TABLE IF NOT EXISTS user (
    `id` int(8) NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `user_phone` varchar(20) NOT NULL DEFAULT '',
    `user_name` varchar(100) NOT NULL DEFAULT '',
    `user_avatar` varchar(200) NOT NULL DEFAULT '',
    `createtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP 
) DEFAULT CHARSET=utf8;
GO;

#活动主表
CREATE TABLE IF NOT EXISTS activity (
    `id` int(8) NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `title` varchar(100) NOT NULL,
    `start_time` int(10) NOT NULL DEFAULT 0,
    `end_time` int(10) NOT NULL DEFAULT 0,
    `createtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP 
) DEFAULT CHARSET=utf8;
GO;

#发布积攒活动文章
CREATE TABLE IF NOT EXISTS act_article (
    `id` int(8) NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `act_id` int(8) NOT NULL DEFAULT 0,
    `good_count` int(8) NOT NULL DEFAULT 0,
    `user_id` int(8) NOT NULL DEFAULT 0,
    `content` text,
    `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) DEFAULT CHARSET=utf8;
GO;

#创建活动iduser索引
ALTER TABLE act_article ADD INDEX INDEX_ACT (act_id);
GO;
ALTER TABLE act_article ADD INDEX INDEX_USER (user_id);
GO;

#发布积攒活动文章图片
CREATE TABLE IF NOT EXISTS act_article_img (
    `id` int(8) NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `article_id` int(8) NOT NULL DEFAULT 0,
    `img_url` varchar(200) DEFAULT '',
    `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) DEFAULT CHARSET=utf8;
GO;

#创建活动id
ALTER TABLE act_article_img ADD INDEX INDEX_ACT (article_id);
GO;

#发布积攒活动文章点赞
CREATE TABLE IF NOT EXISTS act_article_good (
    `id` int(8) NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `act_id` int(8) NOT NULL DEFAULT 0,
    `article_id` int(8) NOT NULL DEFAULT 0,
    `user_id` int(8) NOT NULL DEFAULT 0,
    `ip` varchar(20) NOT NULL DEFAULT '',
    `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) DEFAULT CHARSET=utf8;
GO;

#创建活动idip索引
ALTER TABLE act_article_good ADD INDEX INDEX_ACT_IP (act_id, article_id, ip);
GO;