update_20170328_1_to_20170405_1.sql 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*==============================================================*/
  2. /* DBMS name: MySQL 5.0 */
  3. /* Created on: 2017/4/5 22:18:07 */
  4. /*==============================================================*/
  5. drop table if exists tmp_cms_article;
  6. rename table cms_article to tmp_cms_article;
  7. drop table if exists cms_book;
  8. drop table if exists tmp_cms_category;
  9. rename table cms_category to tmp_cms_category;
  10. drop table if exists tmp_cms_comment;
  11. rename table cms_comment to tmp_cms_comment;
  12. drop table if exists tmp_cms_tag;
  13. rename table cms_tag to tmp_cms_tag;
  14. drop table if exists cms_user;
  15. /*==============================================================*/
  16. /* Table: cms_article */
  17. /*==============================================================*/
  18. create table cms_article
  19. (
  20. article_id int(10) unsigned not null auto_increment comment '文章编号',
  21. topic_id int comment '所属专题',
  22. title varchar(200) not null comment '文章标题',
  23. author varchar(50) default NULL comment '文章原作者',
  24. fromurl varchar(300) default NULL comment '转载来源网址',
  25. image varchar(300) default NULL comment '封面图',
  26. keywords varchar(100) default NULL comment '关键字',
  27. description varchar(500) default NULL comment '简介',
  28. type tinyint(4) not null default 1 comment '类型(1:普通,2:热门...)',
  29. allowcomments tinyint(4) not null default 1 comment '是否允许评论(0:不允许,1:允许)',
  30. status tinyint(4) not null default 1 comment '状态(-1:不通过,0未审核,1:通过)',
  31. content mediumtext comment '内容',
  32. user_id int(10) unsigned not null comment '发布人id',
  33. readnumber int(10) unsigned not null default 0 comment '阅读数量',
  34. top int not null default 0 comment '置顶等级',
  35. system_id int comment '所属系统',
  36. ctime bigint(20) unsigned not null comment '创建时间',
  37. orders bigint(20) unsigned not null comment '排序',
  38. primary key (article_id),
  39. key cms_article_orders (orders)
  40. )
  41. ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='文章表';
  42. alter table cms_article comment '文章表';
  43. insert into cms_article (article_id, topic_id, title, author, fromurl, image, keywords, description, type, allowcomments, status, content, user_id, readnumber, ctime, orders)
  44. select article_id, topic_id, title, author, fromurl, image, keywords, description, type, allowcomments, status, content, user_id, readnumber, ctime, orders
  45. from tmp_cms_article;
  46. /*==============================================================*/
  47. /* Table: cms_category */
  48. /*==============================================================*/
  49. create table cms_category
  50. (
  51. category_id int(10) unsigned not null auto_increment comment '类目编号',
  52. pid int(10) unsigned comment '上级编号',
  53. level tinyint(4) not null comment '层级',
  54. name varchar(20) not null comment '名称',
  55. description varchar(200) default NULL comment '描述',
  56. icon varchar(50) default NULL comment '图标',
  57. type tinyint(3) not null default 1 comment '类型(1:普通,2:热门...)',
  58. alias varchar(20) default NULL comment '别名',
  59. system_id int comment '所属系统',
  60. ctime bigint(20) unsigned not null comment '创建时间',
  61. orders bigint(255) unsigned not null comment '排序',
  62. primary key (category_id),
  63. key cms_category_orders (orders),
  64. key cms_category_pid (pid),
  65. key cms_category_alias (alias),
  66. key cms_category_level (level)
  67. )
  68. ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COMMENT='类目表';
  69. alter table cms_category comment '类目表';
  70. insert into cms_category (category_id, pid, level, name, description, icon, type, alias, ctime, orders)
  71. select category_id, pid, level, name, description, icon, type, alias, ctime, orders
  72. from tmp_cms_category;
  73. /*==============================================================*/
  74. /* Table: cms_comment */
  75. /*==============================================================*/
  76. create table cms_comment
  77. (
  78. comment_id int(10) unsigned not null auto_increment comment '编号',
  79. pid int(10) unsigned default NULL comment '回复楼中楼编号回复楼中楼编号',
  80. article_id int(10) unsigned not null comment '文章编号',
  81. user_id int(10) unsigned not null comment '用户编号',
  82. content text not null comment '评论内容',
  83. status tinyint(4) not null default 1 comment '状态(-1:不通过,0:未审核,1:通过)',
  84. ip varchar(30) default NULL comment '评论人ip地址',
  85. agent varchar(200) default NULL comment '评论人终端信息',
  86. system_id int comment '所属系统',
  87. ctime bigint(20) not null comment '创建时间',
  88. primary key (comment_id),
  89. key cms_comment_article_id (article_id)
  90. )
  91. ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  92. alter table cms_comment comment '评论表';
  93. insert into cms_comment (comment_id, pid, article_id, user_id, content, status, ip, agent, ctime)
  94. select comment_id, pid, article_id, user_id, content, status, ip, agent, ctime
  95. from tmp_cms_comment;
  96. /*==============================================================*/
  97. /* Table: cms_system */
  98. /*==============================================================*/
  99. create table cms_system
  100. (
  101. system_id int unsigned not null auto_increment comment '编号',
  102. name varchar(20) not null comment '系统名称',
  103. code varchar(20) comment '别名',
  104. description varchar(300) comment '描述',
  105. ctime bigint comment '创建时间',
  106. orders bigint comment '排序',
  107. primary key (system_id)
  108. );
  109. alter table cms_system comment '系统管理';
  110. /*==============================================================*/
  111. /* Table: cms_tag */
  112. /*==============================================================*/
  113. create table cms_tag
  114. (
  115. tag_id int(10) unsigned not null auto_increment comment '标签编号',
  116. name varchar(20) not null comment '名称',
  117. description varchar(200) default NULL comment '描述',
  118. icon varchar(50) default NULL comment '图标',
  119. type tinyint(4) not null default 1 comment '类型(1:普通,2:热门...)',
  120. alias varchar(20) default NULL comment '别名',
  121. system_id int comment '所属系统',
  122. ctime bigint(20) unsigned not null comment '创建时间',
  123. orders bigint(20) unsigned not null comment '排序',
  124. primary key (tag_id),
  125. key cms_tag_orders (orders),
  126. key cms_tag_alias (alias)
  127. )
  128. ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='标签表';
  129. alter table cms_tag comment '标签表';
  130. insert into cms_tag (tag_id, name, description, icon, type, alias, ctime, orders)
  131. select tag_id, name, description, icon, type, alias, ctime, orders
  132. from tmp_cms_tag;
  133. alter table cms_article add constraint FK_Reference_30 foreign key (topic_id)
  134. references cms_topic (topic_id) on delete restrict on update restrict;
  135. alter table cms_article_category add constraint FK_Reference_7 foreign key (category_id)
  136. references cms_category (category_id) on delete cascade on update cascade;
  137. alter table cms_article_category add constraint FK_Reference_8 foreign key (article_id)
  138. references cms_article (article_id) on delete cascade on update cascade;
  139. alter table cms_article_tag add constraint FK_Reference_3 foreign key (article_id)
  140. references cms_article (article_id) on delete cascade on update cascade;
  141. alter table cms_article_tag add constraint FK_Reference_4 foreign key (tag_id)
  142. references cms_tag (tag_id) on delete cascade on update cascade;
  143. alter table cms_category add constraint FK_Reference_10 foreign key (pid)
  144. references cms_category (category_id) on delete set null on update restrict;
  145. alter table cms_category_tag add constraint FK_Reference_5 foreign key (category_id)
  146. references cms_category (category_id) on delete cascade on update cascade;
  147. alter table cms_category_tag add constraint FK_Reference_6 foreign key (tag_id)
  148. references cms_tag (tag_id) on delete cascade on update cascade;
  149. alter table cms_comment add constraint FK_Reference_1 foreign key (article_id)
  150. references cms_article (article_id) on delete cascade on update cascade;
  151. alter table cms_comment add constraint FK_Reference_2 foreign key (pid)
  152. references cms_comment (comment_id) on delete cascade on update cascade;