m160806_074300_create_message_table.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. use yii\db\Migration;
  3. /**
  4. * Handles the creation for table `{{%message}}`.
  5. */
  6. class m160806_074300_create_message_table extends Migration
  7. {
  8. public $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
  9. /**
  10. * @inheritdoc
  11. */
  12. public function up()
  13. {
  14. $this->createTable('{{%message}}', [
  15. 'id' => $this->primaryKey(),
  16. 'from_uid' => $this->integer(11)->notNull(),
  17. 'to_uid' => $this->integer(11)->notNull(),
  18. 'message_id' => $this->integer(11)->notNull()->comment('消息ID'),
  19. 'read' => $this->smallInteger(1)->notNull()->defaultValue(0)->comment('是否阅读')
  20. ], $this->tableOptions);
  21. $this->createTable('{{%message_data}}', [
  22. 'id' => $this->primaryKey(),
  23. 'content' => $this->text()->comment('消息内容'),
  24. 'group' => $this->string(128),
  25. 'created_at' => $this->integer(10)->notNull()
  26. ], $this->tableOptions);
  27. }
  28. /**
  29. * @inheritdoc
  30. */
  31. public function down()
  32. {
  33. $this->dropTable('{{%message}}');
  34. $this->dropTable('{{%message_data}}');
  35. }
  36. }