m161215_024158_create_book_table.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. use yii\db\Migration;
  3. /**
  4. * Handles the creation for table `{{%book}}`.
  5. */
  6. class m161215_024158_create_book_table extends Migration
  7. {
  8. /**
  9. * @inheritdoc
  10. */
  11. public function up()
  12. {
  13. $this->createTable('{{%book}}', [
  14. 'id' => $this->primaryKey(),
  15. 'book_name' => $this->string(50)->notNull()->comment('书名'),
  16. 'book_author' => $this->integer(11)->notNull()->comment('作者'),
  17. 'book_link' => $this->string(128)->comment('书外链'),
  18. 'book_description' => $this->string(1000)->notNull()->comment('书简介'),
  19. 'category_id' => $this->integer(11)->notNull()->comment('书分类'),
  20. 'created_at' => $this->integer()->notNull(),
  21. 'updated_at' => $this->integer()->notNull(),
  22. 'view' => $this->integer()->notNull()->defaultValue(0)
  23. ]);
  24. $this->createTable('{{%book_chapter}}', [
  25. 'id' => $this->primaryKey(),
  26. 'book_id' => $this->integer(11)->notNull()->comment('书'),
  27. 'chapter_name' => $this->string(80)->notNull()->comment('章节标题'),
  28. 'chapter_body' => $this->text()->comment('章节正文'),
  29. 'pid' => $this->integer(11)->notNull()->defaultValue(0),
  30. 'sort' => $this->smallInteger(1)->notNull()->defaultValue(0),
  31. 'created_at' => $this->integer()->notNull(),
  32. 'updated_at' => $this->integer()->notNull(),
  33. ]);
  34. $this->createTable('{{%book_category}}', [
  35. 'id' => $this->primaryKey(),
  36. 'category_name' => $this->string(80)->notNull()->comment('分类名'),
  37. 'created_at' => $this->integer()->notNull(),
  38. 'updated_at' => $this->integer()->notNull(),
  39. ]);
  40. }
  41. /**
  42. * @inheritdoc
  43. */
  44. public function down()
  45. {
  46. $this->dropTable('{{%book}}');
  47. $this->dropTable('{{%book_chapter}}');
  48. $this->dropTable('{{%book_category}}');
  49. }
  50. }