m190130_070831_add_article_teamplate.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. use common\helpers\DbDriverHelper;
  3. use yii\db\Migration;
  4. /**
  5. * Class m190130_070831_add_article_teamplate
  6. */
  7. class m190130_070831_add_article_teamplate extends Migration
  8. {
  9. /**
  10. * {@inheritdoc}
  11. */
  12. public function safeUp()
  13. {
  14. $categoryTemplate = $this->string()->after("sort")->defaultValue("")->notNull();
  15. $categoryArticleTemplate = $this->string()->after("template")->defaultValue("")->notNull();
  16. $articleTemplate = $this->string()->after("flag_picture")->defaultValue("")->notNull();
  17. if (!DbDriverHelper::isSqlite()) {
  18. $categoryTemplate->comment("category page template path");
  19. $categoryArticleTemplate->comment("article detail page template path");
  20. $articleTemplate->comment("article detail page template path");
  21. }
  22. $this->addColumn("{{%category}}","template", $categoryTemplate);
  23. $this->addColumn("{{%category}}","article_template", $categoryArticleTemplate);
  24. $this->addColumn("{{%article}}", "template", $articleTemplate);
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function safeDown()
  30. {
  31. $this->dropColumn("{{%category}}", "template");
  32. $this->dropColumn("{{%category}}", "article_template");
  33. $this->dropColumn("{{%article}}", "template");
  34. }
  35. /*
  36. // Use up()/down() to run migration code without a transaction.
  37. public function up()
  38. {
  39. }
  40. public function down()
  41. {
  42. echo "m190130_070831_add_article_teamplate cannot be reverted.\n";
  43. return false;
  44. }
  45. */
  46. }