m160721_134955_create_carousel_table.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. use yii\db\Schema;
  3. use yii\db\Migration;
  4. class m160721_134955_create_carousel_table extends Migration
  5. {
  6. public function safeUp()
  7. {
  8. $tableOptions = null;
  9. if ($this->db->driverName === 'mysql') {
  10. $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
  11. }
  12. $this->createTable('{{%carousel}}', [
  13. 'id' => $this->primaryKey(),
  14. 'key' => $this->string(128)->notNull(),
  15. 'title' => $this->string(255)->notNull(),
  16. 'status' => $this->smallInteger()->defaultValue(0)
  17. ], $tableOptions);
  18. $this->createTable('{{%carousel_item}}', [
  19. 'id' => $this->primaryKey(),
  20. 'carousel_id' => $this->integer()->notNull(),
  21. 'url' => $this->string(1024),
  22. 'caption' => $this->string(1024),
  23. 'image' => $this->string(255),
  24. 'status' => $this->smallInteger()->notNull()->defaultValue(0),
  25. 'sort' => $this->integer()->defaultValue(0),
  26. 'created_at' => $this->integer(),
  27. 'updated_at' => $this->integer(),
  28. ], $tableOptions);
  29. }
  30. public function safeDown()
  31. {
  32. $this->dropTable('{{%carousel_item}}');
  33. $this->dropTable('{{%carousel}}');
  34. }
  35. }