m130524_201442_init.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <?php
  2. use yii\db\Migration;
  3. use yii\db\Schema;
  4. class m130524_201442_init extends Migration
  5. {
  6. public $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
  7. public function safeUp()
  8. {
  9. $this->execute('SET foreign_key_checks = 0');
  10. // admin_log
  11. $this->createTable('{{%admin_log}}', [
  12. 'id' => Schema::TYPE_PK,
  13. 'route' => Schema::TYPE_STRING . "(255) NOT NULL DEFAULT ''",
  14. 'description' => Schema::TYPE_TEXT . " NULL",
  15. 'created_at' => Schema::TYPE_INTEGER . "(10) NOT NULL",
  16. 'user_id' => Schema::TYPE_INTEGER . "(10) NOT NULL DEFAULT '0'",
  17. 'ip' => Schema::TYPE_BIGINT . "(20) NOT NULL DEFAULT '0'",
  18. ], $this->tableOptions);
  19. // article
  20. $this->createTable('{{%article}}', [
  21. 'id' => Schema::TYPE_PK,
  22. 'title' => Schema::TYPE_STRING . "(50) NOT NULL COMMENT '标题'",
  23. 'category' => Schema::TYPE_STRING . "(50) NOT NULL COMMENT '分类'",
  24. 'category_id' => Schema::TYPE_INTEGER . "(11) NOT NULL",
  25. 'status' => Schema::TYPE_BOOLEAN . " NOT NULL COMMENT '状态'",
  26. 'view' => Schema::TYPE_INTEGER . "(11) NOT NULL DEFAULT '0'",
  27. 'is_top' => $this->smallInteger(1)->notNull()->defaultValue(0)->comment('是否置顶'),
  28. 'is_hot' => $this->smallInteger(1)->notNull()->defaultValue(0)->comment('是否热门'),
  29. 'is_best' => $this->smallInteger(1)->notNull()->defaultValue(0)->comment('是否精华'),
  30. 'description' => $this->string(255)->notNull()->defaultValue('')->comment('摘要'),
  31. 'user_id' => Schema::TYPE_INTEGER . "(11) NOT NULL DEFAULT '0'",
  32. 'source' => $this->string(255)->notNull()->defaultValue('')->comment('来源'),
  33. 'deleted_at' => Schema::TYPE_INTEGER . "(10)",
  34. 'favourite' => Schema::TYPE_INTEGER . "(11) NOT NULL DEFAULT '0'",
  35. 'published_at' => Schema::TYPE_INTEGER . "(10) NOT NULL DEFAULT '0'",
  36. 'created_at' => Schema::TYPE_INTEGER . "(10) NOT NULL",
  37. 'updated_at' => Schema::TYPE_INTEGER . "(10) NOT NULL",
  38. ], $this->tableOptions);
  39. $this->createIndex('index_published_at', '{{%article}}', 'published_at');
  40. // article_data
  41. $this->createTable('{{%article_data}}', [
  42. 'id' => Schema::TYPE_INTEGER . "(11) NOT NULL",
  43. 'content' => Schema::TYPE_TEXT . " NOT NULL",
  44. 'markdown' => $this->smallInteger(1)->notNull()->defaultValue(0)->comment('是否markdown格式'),
  45. 'PRIMARY KEY (id)',
  46. ], $this->tableOptions);
  47. // article_tag
  48. $this->createTable('{{%article_tag}}', [
  49. 'article_id' => Schema::TYPE_INTEGER . "(10) NOT NULL",
  50. 'tag_id' => Schema::TYPE_INTEGER . "(10) NOT NULL",
  51. ], $this->tableOptions);
  52. // meta
  53. $this->createTable('{{%meta}}', [
  54. 'id' => $this->primaryKey(),
  55. 'title' => $this->string(128),
  56. 'keywords' => $this->string(128),
  57. 'description' => $this->string(128),
  58. 'entity' => $this->string(80),
  59. 'entity_id' => $this->integer()
  60. ], $this->tableOptions);
  61. // auth
  62. $this->createTable('{{%auth}}', [
  63. 'id' => Schema::TYPE_PK,
  64. 'user_id' => Schema::TYPE_INTEGER . "(11) NOT NULL",
  65. 'source' => Schema::TYPE_STRING . "(255) NOT NULL",
  66. 'source_id' => Schema::TYPE_STRING . "(255) NOT NULL",
  67. ], $this->tableOptions);
  68. // category
  69. $this->createTable('{{%category}}', [
  70. 'id' => Schema::TYPE_PK,
  71. 'title' => Schema::TYPE_STRING . "(50) NOT NULL COMMENT '名字'",
  72. 'pid' => Schema::TYPE_INTEGER . "(11) NOT NULL DEFAULT '0' COMMENT '父id'",
  73. 'created_at' => Schema::TYPE_INTEGER . "(10) NOT NULL",
  74. 'updated_at' => Schema::TYPE_INTEGER . "(10) NOT NULL",
  75. 'slug' => Schema::TYPE_STRING . "(20) NOT NULL",
  76. 'description' => Schema::TYPE_STRING . "(1000) NOT NULL DEFAULT ''",
  77. 'article' => Schema::TYPE_INTEGER . "(10) NOT NULL DEFAULT '0'",
  78. 'sort' => Schema::TYPE_BOOLEAN . " NOT NULL DEFAULT '0'",
  79. 'allow_publish' => $this->smallInteger(1)->defaultValue('1')->comment('是否允许发布内容')
  80. ], $this->tableOptions);
  81. // comment
  82. $this->createTable('{{%comment}}', [
  83. 'id' => Schema::TYPE_PK,
  84. 'user_id' => Schema::TYPE_INTEGER . "(11) NOT NULL",
  85. 'user_ip' => $this->string(20)->comment('用户ip')->defaultValue(''),
  86. 'entity' => Schema::TYPE_STRING . "(80) NOT NULL",
  87. 'entity_id' => Schema::TYPE_INTEGER . "(11) NOT NULL",
  88. 'content' => Schema::TYPE_TEXT . " NOT NULL COMMENT '内容'",
  89. 'parent_id' => Schema::TYPE_INTEGER . "(11) NOT NULL DEFAULT '0'",
  90. 'reply_uid' => $this->integer(11)->defaultValue('0'),
  91. 'is_top' => Schema::TYPE_SMALLINT . "(1) NOT NULL DEFAULT '0'",
  92. 'status' => Schema::TYPE_SMALLINT . "(1) NOT NULL DEFAULT '1'",
  93. 'created_at' => Schema::TYPE_INTEGER . "(10) NOT NULL",
  94. 'updated_at' => Schema::TYPE_INTEGER . "(10) NOT NULL",
  95. ], $this->tableOptions);
  96. $this->createIndex('entity', '{{%comment}}', ['entity', 'entity_id']);
  97. // comment_info
  98. $this->createTable('{{%comment_info}}', [
  99. 'id' => Schema::TYPE_PK,
  100. 'entity' => $this->string(80)->notNull(),
  101. 'entity_id' => $this->integer(11)->notNull(),
  102. 'status' => $this->boolean()->notNull()->defaultValue(1),
  103. 'total' => $this->integer(11)->notNull()
  104. ], $this->tableOptions);
  105. $this->createIndex('entity', '{{%comment_info}}', ['entity', 'entity_id']);
  106. // favourite
  107. $this->createTable('{{%favourite}}', [
  108. 'id' => Schema::TYPE_PK,
  109. 'user_id' => Schema::TYPE_INTEGER . "(11) NOT NULL",
  110. 'article_id' => Schema::TYPE_INTEGER . "(11) NOT NULL",
  111. 'created_at' => Schema::TYPE_INTEGER . "(10) NOT NULL",
  112. ], $this->tableOptions);
  113. // gather
  114. $this->createTable('{{%gather}}', [
  115. 'id' => Schema::TYPE_PK,
  116. 'url_org' => Schema::TYPE_STRING . "(255) NOT NULL",
  117. 'created_at' => Schema::TYPE_INTEGER . "(10) NOT NULL",
  118. 'updated_at' => Schema::TYPE_INTEGER . "(10) NOT NULL",
  119. ], $this->tableOptions);
  120. // page
  121. $this->createTable('{{%page}}', [
  122. 'id' => Schema::TYPE_PK,
  123. 'use_layout' => Schema::TYPE_BOOLEAN . " NOT NULL DEFAULT '1' COMMENT '0:不使用1:使用'",
  124. 'content' => Schema::TYPE_TEXT . " NOT NULL COMMENT '内容'",
  125. 'title' => Schema::TYPE_STRING . "(50) NOT NULL COMMENT '标题'",
  126. 'slug' => Schema::TYPE_STRING . "(50) NOT NULL DEFAULT ''",
  127. 'markdown' => $this->smallInteger(1)->defaultValue(0)->comment('是否markdown格式'),
  128. 'created_at' => Schema::TYPE_INTEGER . "(10) NULL",
  129. 'updated_at' => Schema::TYPE_INTEGER . "(10) NULL",
  130. ], $this->tableOptions);
  131. // reward
  132. $this->createTable('{{%reward}}', [
  133. 'id' => Schema::TYPE_PK,
  134. 'article_id' => Schema::TYPE_INTEGER . "(11) NOT NULL",
  135. 'user_id' => Schema::TYPE_INTEGER . "(11) NOT NULL",
  136. 'money' => Schema::TYPE_INTEGER . "(11) NOT NULL",
  137. 'comment' => $this->string(50)->defaultValue('')->comment('留言'),
  138. 'created_at' => Schema::TYPE_INTEGER . "(10) NOT NULL",
  139. 'updated_at' => Schema::TYPE_INTEGER . "(10) NOT NULL",
  140. ], $this->tableOptions);
  141. // sign_info 签到表
  142. $this->createTable('{{%sign_info}}', [
  143. 'id' => Schema::TYPE_PK,
  144. 'user_id' => Schema::TYPE_INTEGER . "(11) NOT NULL",
  145. 'last_sign_at' => Schema::TYPE_INTEGER . "(10) NOT NULL COMMENT '上次签到时间'",
  146. 'times' => Schema::TYPE_INTEGER . "(11) NOT NULL COMMENT '总签到次数'",
  147. 'continue_times' => Schema::TYPE_INTEGER . "(11) NOT NULL COMMENT '连续签到次数'",
  148. ], $this->tableOptions);
  149. // sign 签到表
  150. $this->createTable('{{%sign}}', [
  151. 'id' => Schema::TYPE_PK,
  152. 'user_id' => Schema::TYPE_INTEGER . "(11) NOT NULL",
  153. 'sign_at' => Schema::TYPE_INTEGER . "(10) NOT NULL COMMENT '签到时间'",
  154. ], $this->tableOptions);
  155. // spider
  156. $this->createTable('{{%spider}}', [
  157. 'id' => Schema::TYPE_PK,
  158. 'name' => Schema::TYPE_STRING . "(20) NOT NULL COMMENT '标识'",
  159. 'title' => Schema::TYPE_STRING . "(100) NOT NULL COMMENT '名称'",
  160. 'domain' => Schema::TYPE_STRING . "(255) NOT NULL COMMENT '域名'",
  161. 'page_dom' => Schema::TYPE_STRING . "(255) NOT NULL COMMENT '分页链接元素'",
  162. 'list_dom' => Schema::TYPE_STRING . "(255) NOT NULL COMMENT '列表链接元素'",
  163. 'time_dom' => Schema::TYPE_STRING . "(255) NULL COMMENT '内容页时间元素'",
  164. 'content_dom' => Schema::TYPE_STRING . "(255) NOT NULL COMMENT '内容页内容元素'",
  165. 'title_dom' => Schema::TYPE_STRING . "(255) NOT NULL COMMENT '内容页标题元素'",
  166. 'target_category' => Schema::TYPE_STRING . "(255) NOT NULL COMMENT '目标分类'",
  167. 'target_category_url' => Schema::TYPE_STRING . "(255) NOT NULL COMMENT '目标分类地址'",
  168. ], $this->tableOptions);
  169. // system_log
  170. $this->createTable('{{%system_log}}', [
  171. 'id' => Schema::TYPE_BIGPK,
  172. 'level' => Schema::TYPE_INTEGER . "(11) NULL",
  173. 'category' => Schema::TYPE_STRING . "(255) NULL",
  174. 'log_time' => Schema::TYPE_DOUBLE . " NULL",
  175. 'prefix' => Schema::TYPE_TEXT . " NULL",
  176. 'message' => Schema::TYPE_TEXT . " NULL",
  177. ], $this->tableOptions);
  178. // tag
  179. $this->createTable('{{%tag}}', [
  180. 'id' => Schema::TYPE_PK,
  181. 'name' => Schema::TYPE_STRING . "(100) NOT NULL",
  182. 'article' => Schema::TYPE_INTEGER . "(11) NOT NULL DEFAULT '0' COMMENT '有该标签的文章数'",
  183. ], $this->tableOptions);
  184. // vote
  185. $this->createTable('{{%vote}}', [
  186. 'id' => Schema::TYPE_PK,
  187. 'entity' => Schema::TYPE_STRING . "(80) NOT NULL",
  188. 'entity_id' => Schema::TYPE_INTEGER . "(11) NOT NULL",
  189. 'user_id' => Schema::TYPE_INTEGER . "(11) NOT NULL",
  190. 'created_at' => Schema::TYPE_INTEGER . "(10) NOT NULL",
  191. 'updated_at' => Schema::TYPE_INTEGER . "(10) NOT NULL",
  192. 'action' => Schema::TYPE_STRING . "(20) NOT NULL DEFAULT 'up' COMMENT 'up or down'",
  193. ], $this->tableOptions);
  194. //vote_info
  195. $this->createTable('{{%vote_info}}', [
  196. 'id' => Schema::TYPE_PK,
  197. 'entity' => $this->string(80)->notNull(),
  198. 'entity_id' => $this->integer(11)->notNull(),
  199. 'up' => $this->integer(11)->notNull()->defaultValue('0')->comment('顶数'),
  200. 'down' => $this->integer(11)->notNull()->defaultValue('0')->comment('踩数'),
  201. ], $this->tableOptions);
  202. $this->createIndex('entity', '{{%vote_info}}', ['entity', 'entity_id']);
  203. // suggest
  204. $this->createTable('{{%suggest}}', [
  205. 'title' => $this->string(128)->notNull(),
  206. 'content' => $this->string(1000)->notNull(),
  207. 'created_at' => $this->integer()->notNull(),
  208. 'user_id' => $this->integer(11)->notNull()
  209. ]);
  210. $this->insert('{{%page}}', [
  211. 'use_layout' => 1,
  212. 'content' => '关于我们',
  213. 'title' => '关于我们',
  214. 'slug' => 'aboutus',
  215. 'created_at' => time(),
  216. 'updated_at' => time()
  217. ]);
  218. $this->insert('{{%category}}', [
  219. 'slug' => 'default',
  220. 'title' => '默认',
  221. 'allow_publish' => '2',
  222. 'created_at' => time(),
  223. 'updated_at' => time()
  224. ]);
  225. $this->execute('SET foreign_key_checks = 1');
  226. }
  227. public function safeDown()
  228. {
  229. $this->execute('SET foreign_key_checks = 0');
  230. $this->dropTable('{{%admin_log}}');
  231. $this->dropTable('{{%article}}');
  232. $this->dropTable('{{%article_data}}');
  233. $this->dropTable('{{%article_tag}}');
  234. $this->dropTable('{{%meta}}');
  235. $this->dropTable('{{%auth}}');
  236. $this->dropTable('{{%category}}');
  237. $this->dropTable('{{%comment}}');
  238. $this->dropTable('{{%comment_info}}');
  239. $this->dropTable('{{%favourite}}');
  240. $this->dropTable('{{%gather}}');
  241. $this->dropTable('{{%page}}');
  242. $this->dropTable('{{%reward}}');
  243. $this->dropTable('{{%sign}}');
  244. $this->dropTable('{{%spider}}');
  245. $this->dropTable('{{%system_log}}');
  246. $this->dropTable('{{%tag}}');
  247. $this->dropTable('{{%vote}}');
  248. $this->dropTable('{{%vote_info}}');
  249. $this->execute('SET foreign_key_checks = 1');
  250. }
  251. }