m160912_051818_create_album_table.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. use yii\db\Migration;
  3. /**
  4. * Handles the creation for table `{{%album}}`.
  5. */
  6. class m160912_051818_create_album_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('{{%album}}', [
  15. 'id' => $this->primaryKey(),
  16. 'name' => $this->string(128)->notNull()->comment('相册名'),
  17. 'description' => $this->string()->comment('相册描述'),
  18. 'owner_id' => $this->integer(11)->notNull()->comment('相册所有者'),
  19. 'user_id' => $this->integer(11)->notNull()->comment('创建者'),
  20. 'created_at' => $this->integer(10)->notNull(),
  21. 'updated_at' => $this->integer(10)->notNull()
  22. ], $this->tableOptions);
  23. $this->createTable('{{%album_attachment}}', [
  24. 'album_id' => $this->integer(11)->notNull()->comment('相册ID'),
  25. 'attachment_id' => $this->integer(11)->notNull()->comment('附件ID'),
  26. ], $this->tableOptions);
  27. }
  28. /**
  29. * @inheritdoc
  30. */
  31. public function down()
  32. {
  33. $this->dropTable('{{%album}}');
  34. $this->dropTable('{{%album_attachment}}');
  35. }
  36. }