m160622_073825_create_notify.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. use yii\db\Migration;
  3. use yii\db\Schema;
  4. /**
  5. * 通知
  6. */
  7. class m160622_073825_create_notify extends Migration
  8. {
  9. /**
  10. * @inheritdoc
  11. */
  12. public function up()
  13. {
  14. $tableOptions = null;
  15. if ($this->db->driverName === 'mysql') {
  16. $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
  17. }
  18. // notify
  19. $this->createTable('{{%notify}}', [
  20. 'id' => $this->primaryKey(),
  21. 'from_uid' => $this->integer(11)->notNull(),
  22. 'to_uid' => $this->integer(11)->notNull(),
  23. 'category_id' => $this->integer(11)->comment('通知分类ID'),
  24. 'extra' => $this->text()->comment('附加信息'),
  25. 'created_at' => $this->integer(10)->notNull(),
  26. 'read' => $this->boolean()->notNull()->defaultValue(0),
  27. ], $tableOptions);
  28. $this->createIndex('notify_from_uid_index', '{{%notify}}', 'from_uid');
  29. $this->createIndex('notify_to_uid_index', '{{%notify}}', 'to_uid');
  30. $this->createIndex('notify_category_id_index', '{{%notify}}', 'category_id');
  31. // notify_category
  32. $this->createTable('{{%notify_category}}', [
  33. 'id' => $this->primaryKey(),
  34. 'name' => $this->string(50)->unique(),
  35. 'title' => $this->string(255),
  36. 'content' => $this->string(255),
  37. ], $tableOptions);
  38. $this->batchInsert('{{%notify_category}}', ['name', 'title', 'content'], [
  39. ['reply', '回复了你的评论', '{extra.comment}'],
  40. ['suggest', '给你留言了', '{extra.title}'],
  41. ['comment_article', '评论了你的文章 {extra.article_title}', '{extra.comment}'],
  42. ['favourite', '收藏了你的文章 {extra.article_title}', null],
  43. ['up_article', '赞了你的文章 {extra.article_title}', null],
  44. ['message', '给你发了私信', '{extra.message}'],
  45. ['reward', '打赏了你的文章 {extra.article_title}', '{extra.money} {extra.comment}'],
  46. ['follow', '关注了你', null],
  47. ['up_follow', '赞了你的评论', null],
  48. ]);
  49. }
  50. /**
  51. * @inheritdoc
  52. */
  53. public function down()
  54. {
  55. $this->dropTable('{{%notify}}');
  56. $this->dropTable('{{%notify_category}}');
  57. }
  58. }