| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace app\migrations;
- use yii\db\Migration;
- use yii\db\Schema;
- /**
- * Class M250908091713AlterQimalGoodsExtra.php
- */
- class M250908094513AlterQimalGoodsExtra extends Migration
- {
- /**
- * {@inheritdoc}
- */
- public function safeUp()
- {
- $this->addColumnIfNotExists(
- 'qimall_goods_extra',
- 'is_member_alone_buy_limit',
- Schema::TYPE_TINYINT . ' DEFAULT 0 COMMENT "是否会员指定等级每月限购数量"'
- );
- $this->addColumnIfNotExists(
- 'qimall_goods_extra',
- 'member_alone_buy_limit_setting',
- Schema::TYPE_TEXT . ' COMMENT "会员指定等级每月限购数量设置"'
- );
- }
- protected function addColumnIfNotExists($table, $column, $type)
- {
- $transaction = $this->db->beginTransaction();
- try {
- $tableSchema = $this->db->getSchema()->getTableSchema($table);
- if ($tableSchema && !isset($tableSchema->columns[$column])) {
- $this->addColumn($table, $column, $type);
- $transaction->commit();
- return true;
- }
- } catch (\Exception $e) {
- $transaction->rollback();
- throw $e;
- }
- return false;
- }
- /**
- * {@inheritdoc}
- */
- public function safeDown()
- {
- echo "M250822175613AlterQimalGoodsExtra.php cannot be reverted.\n";
- return false;
- }
- /*
- // Use up()/down() to run migration code without a transaction.
- public function up()
- {
- }
- public function down()
- {
- echo "M250729084413AlterQimallAddonsStoreGoodsExtra cannot be reverted.\n";
- return false;
- }
- */
- }
|