M250908094513AlterQimalGoodsExtra.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace app\migrations;
  3. use yii\db\Migration;
  4. use yii\db\Schema;
  5. /**
  6. * Class M250908091713AlterQimalGoodsExtra.php
  7. */
  8. class M250908094513AlterQimalGoodsExtra extends Migration
  9. {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public function safeUp()
  14. {
  15. $this->addColumnIfNotExists(
  16. 'qimall_goods_extra',
  17. 'is_member_alone_buy_limit',
  18. Schema::TYPE_TINYINT . ' DEFAULT 0 COMMENT "是否会员指定等级每月限购数量"'
  19. );
  20. $this->addColumnIfNotExists(
  21. 'qimall_goods_extra',
  22. 'member_alone_buy_limit_setting',
  23. Schema::TYPE_TEXT . ' COMMENT "会员指定等级每月限购数量设置"'
  24. );
  25. }
  26. protected function addColumnIfNotExists($table, $column, $type)
  27. {
  28. $transaction = $this->db->beginTransaction();
  29. try {
  30. $tableSchema = $this->db->getSchema()->getTableSchema($table);
  31. if ($tableSchema && !isset($tableSchema->columns[$column])) {
  32. $this->addColumn($table, $column, $type);
  33. $transaction->commit();
  34. return true;
  35. }
  36. } catch (\Exception $e) {
  37. $transaction->rollback();
  38. throw $e;
  39. }
  40. return false;
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function safeDown()
  46. {
  47. echo "M250822175613AlterQimalGoodsExtra.php cannot be reverted.\n";
  48. return false;
  49. }
  50. /*
  51. // Use up()/down() to run migration code without a transaction.
  52. public function up()
  53. {
  54. }
  55. public function down()
  56. {
  57. echo "M250729084413AlterQimallAddonsStoreGoodsExtra cannot be reverted.\n";
  58. return false;
  59. }
  60. */
  61. }