20230324101559_add_show_time_to_material.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. use app\model\DailyWechatArticle;
  3. use think\facade\Db;
  4. use think\migration\Migrator;
  5. use think\migration\db\Column;
  6. class AddShowTimeToMaterial extends Migrator
  7. {
  8. /**
  9. * Change Method.
  10. *
  11. * Write your reversible migrations using this method.
  12. *
  13. * More information on writing migrations is available here:
  14. * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
  15. *
  16. * The following commands can be used in this method and Phinx will
  17. * automatically reverse them when rolling back:
  18. *
  19. * createTable
  20. * renameTable
  21. * addColumn
  22. * renameColumn
  23. * addIndex
  24. * addForeignKey
  25. *
  26. * Remember to call "create()" or "update()" and NOT "save()" when working
  27. * with the Table class.
  28. */
  29. public function change()
  30. {
  31. $this->table('daily_wechat_article')
  32. ->addColumn('show_date', 'date', ['comment'=>'展示时间', 'null'=>true])
  33. ->update();
  34. DailyWechatArticle::where([['show_date', 'NULL', '']])->update([
  35. 'show_date'=>Db::raw('addtime')
  36. ]);
  37. }
  38. }