M250828144953AddGroupBuyActive.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace addons\GroupBuy\console\migrations;
  3. use Yii;
  4. use yii\db\Migration;
  5. /**
  6. * 添加拼团活动表-参团限制次数字段 restrict_rule_num
  7. * Class M250828144953AddGroupBuyActive
  8. */
  9. class M250828144953AddGroupBuyActive extends Migration
  10. {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public function safeUp()
  15. {
  16. try {
  17. if (!$this->columnExists('qimall_addons_group_buy_active', 'restrict_rule_num')) {
  18. $sql = <<<SQL
  19. ALTER TABLE `qimall_addons_group_buy_active` ADD COLUMN `restrict_rule_num` int(11) NOT NULL DEFAULT 0 COMMENT '参团限制次数';
  20. SQL;
  21. $this->execute($sql);
  22. }
  23. }catch (\Exception $e) {}
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function safeDown()
  29. {
  30. return false;
  31. }
  32. protected function columnExists($tableName, $columnName)
  33. {
  34. $tableSchema = Yii::$app->db->getTableSchema($tableName, true);
  35. return $tableSchema && in_array($columnName, $tableSchema->columnNames);
  36. }
  37. }