m160718_040058_create_article_module_table.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. use yii\db\Migration;
  3. /**
  4. * Handles the creation for table `{{%article_module}}`.
  5. */
  6. class m160718_040058_create_article_module_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('{{%article_module}}', [
  18. 'id' => $this->primaryKey(),
  19. 'name' => $this->string(50),
  20. 'title' => $this->string(50),
  21. ], $tableOptions);
  22. $this->createTable('{{%article_exhibition}}', [
  23. 'id' => $this->integer(11),
  24. 'start_at' => $this->dateTime()->comment('开始时间'),
  25. 'end_at' => $this->dateTime()->comment('结束时间'),
  26. 'city' => $this->string(50)->comment('举办城市'),
  27. 'address' => $this->string(255)->comment('举办地址'),
  28. 'PRIMARY KEY (id)',
  29. ], $tableOptions);
  30. $moduleColumn = new \yii\db\ColumnSchemaBuilder('string');
  31. $moduleColumn->comment('文档类型');
  32. $moduleColumn->defaultValue('base');// 默认普通文章
  33. $this->addColumn('{{%article}}', 'module', $moduleColumn);
  34. $this->addColumn('{{%category}}', 'module', $moduleColumn);
  35. $this->createTable('{{%article_download}}', [
  36. 'id' => $this->integer(11),
  37. 'content' => $this->text(),
  38. 'PRIMARY KEY (id)',
  39. ], $tableOptions);
  40. $this->createTable('{{%article_photo}}', [
  41. 'id' => $this->integer(11),
  42. 'PRIMARY KEY (id)',
  43. ], $tableOptions);
  44. $this->insert('{{%article_module}}', [
  45. 'name' => 'base',
  46. 'title' => '普通',
  47. ]);
  48. $this->insert('{{%article_module}}', [
  49. 'name' => 'exhibition',
  50. 'title' => '展会',
  51. ]);
  52. $this->insert('{{%article_module}}', [
  53. 'name' => 'download',
  54. 'title' => '下载',
  55. ]);
  56. $this->insert('{{%article_module}}', [
  57. 'name' => 'photo',
  58. 'title' => '相册',
  59. ]);
  60. }
  61. /**
  62. * @inheritdoc
  63. */
  64. public function down()
  65. {
  66. $this->dropTable('{{%article_module}}');
  67. $this->dropTable('{{%article_exhibition}}');
  68. $this->dropTable('{{%article_download}}');
  69. $this->dropTable('{{%article_photo}}');
  70. $this->dropColumn('{{%article}}', 'module');
  71. $this->dropColumn('{{%category}}', 'module');
  72. }
  73. }