m160722_051000_create_friend_table.php 941 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. use yii\db\Migration;
  3. /**
  4. * Handles the creation for table `{{%friend}}`.
  5. */
  6. class m160722_051000_create_friend_table extends Migration
  7. {
  8. /**
  9. * @inheritdoc
  10. */
  11. public function up()
  12. {
  13. $tableOptions = null;
  14. if ($this->db->driverName === 'mysql') {
  15. $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
  16. }
  17. $this->createTable('{{%friend}}', [
  18. 'owner_id' => $this->integer()->notNull()->comment('自己'),
  19. 'friend_id' => $this->integer()->notNull()->comment('朋友'),
  20. 'created_at' => $this->integer()->notNull(),
  21. 'updated_at' => $this->integer()->notNull(),
  22. ], $tableOptions);
  23. $this->createIndex('friend', '{{%friend}}', ['owner_id', 'friend_id'], true);
  24. }
  25. /**
  26. * @inheritdoc
  27. */
  28. public function down()
  29. {
  30. $this->dropTable('{{%friend}}');
  31. }
  32. }