20230528094938_add_column_live_to_fish_live.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. use think\migration\Migrator;
  3. use think\migration\db\Column;
  4. class AddColumnLiveToFishLive extends Migrator
  5. {
  6. /**
  7. * Change Method.
  8. *
  9. * Write your reversible migrations using this method.
  10. *
  11. * More information on writing migrations is available here:
  12. * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
  13. *
  14. * The following commands can be used in this method and Phinx will
  15. * automatically reverse them when rolling back:
  16. *
  17. * createTable
  18. * renameTable
  19. * addColumn
  20. * renameColumn
  21. * addIndex
  22. * addForeignKey
  23. *
  24. * Remember to call "create()" or "update()" and NOT "save()" when working
  25. * with the Table class.
  26. */
  27. public function change()
  28. {
  29. if ( !$this->table('fish_live')->hasColumn('live_avg_watch_duration')){
  30. $this->table('fish_live')
  31. ->addColumn('live_avg_watch_duration', 'string', array('limit' => 100,'null' => true, 'default'=>'', 'comment'=>'人均停留时长'))->update();
  32. }
  33. if ( !$this->table('fish_live')->hasColumn('live_comment_count')){
  34. $this->table('fish_live')->addColumn('live_comment_count','integer', ['limit'=> 11, 'default'=> 0, 'comment'=> '评论数'])->update();
  35. }
  36. if ( !$this->table('fish_live')->hasColumn('live_follow_count')){
  37. $this->table('fish_live')->addColumn('live_follow_count','integer', ['limit'=> 11, 'default'=> 0, 'comment'=> '关注数'])->update();
  38. }
  39. if ( !$this->table('fish_live')->hasColumn('live_share_count')){
  40. $this->table('fish_live')->addColumn('live_share_count','integer', ['limit'=> 11, 'default'=> 0, 'comment'=> '分享数'])->update();
  41. }
  42. if ( !$this->table('fish_live')->hasColumn('live_count')){
  43. $this->table('fish_live')->addColumn('live_count','integer', ['limit'=> 10, 'default'=> 0, 'comment'=> '直播场次'])->update();
  44. }
  45. }
  46. }