| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace app\migrations;
- use yii\db\Migration;
- /**
- * Class M241204120305AddShippedColumnToOrderDetail
- */
- class M241204120305AddShippedColumnToOrderDetail extends Migration
- {
- /**
- * {@inheritdoc}
- */
- public function safeUp()
- {
- $sql = <<<SQL
- ALTER TABLE `qimall_order_detail`
- ADD COLUMN `shipped_num` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '已发货数量';
- UPDATE `qimall_order_detail` SET `unshipped_num` = `num` WHERE `shipping_status` = 0 and `unshipped_num` = 0;
- UPDATE `qimall_order_detail` SET `shipped_num` = `num` - `unshipped_num`;
- ALTER TABLE `qimall_order_detail`
- DROP COLUMN `unshipped_num`;
- SQL;
- $this->execute($sql);
- }
- /**
- * {@inheritdoc}
- */
- public function safeDown()
- {
- return false;
- }
- /*
- // Use up()/down() to run migration code without a transaction.
- public function up()
- {
- }
- public function down()
- {
- echo "M241204120305AddShippedColumnToOrderDetail cannot be reverted.\n";
- return false;
- }
- */
- }
|