m160717_062452_create_attachment_table.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. use yii\db\Migration;
  3. /**
  4. * Handles the creation for table `{{%attachment}}`.
  5. */
  6. class m160717_062452_create_attachment_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('{{%attachment}}', [
  18. 'id' => $this->primaryKey(),
  19. 'user_id' => $this->integer(11),
  20. 'name' => $this->string(255),
  21. 'title' => $this->string(255),
  22. 'description' => $this->string(255)->null(),
  23. 'path' => $this->string(255)->notNull(),
  24. 'hash' => $this->string(64)->notNull(),
  25. 'size' => $this->integer(11),
  26. 'type' => $this->string(255),
  27. 'extension' => $this->string(255),
  28. 'created_at' => $this->integer(10)->notNull(),
  29. 'updated_at' => $this->integer(10)->notNull()
  30. ], $tableOptions);
  31. $this->createTable('{{%attachment_index}}', [
  32. 'attachment_id' => $this->integer(11)->notNull(),
  33. 'entity' => $this->string(80)->notNull(),
  34. 'entity_id' => $this->integer(11)->notNull(),
  35. 'attribute' => $this->string(20)->notNull()
  36. ], $tableOptions);
  37. }
  38. /**
  39. * @inheritdoc
  40. */
  41. public function down()
  42. {
  43. $this->dropTable('{{%attachment}}');
  44. $this->dropTable('{{%attachment_index}}');
  45. }
  46. }