M241114014502AddUnshippedNumColumnToOrderDetailTable.php 648 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace app\migrations;
  3. use yii\db\Migration;
  4. /**
  5. * Handles adding columns to table `{{%order_detail}}`.
  6. */
  7. class M241114014502AddUnshippedNumColumnToOrderDetailTable extends Migration
  8. {
  9. /**
  10. * {@inheritdoc}
  11. */
  12. public function safeUp()
  13. {
  14. $sql = <<<SQL
  15. ALTER TABLE `qimall_order_detail`
  16. ADD COLUMN `unshipped_num` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '未发货数量';
  17. UPDATE `qimall_order_detail` SET `unshipped_num` = `num` WHERE `shipping_status` = 0;
  18. SQL;
  19. $this->execute($sql);
  20. }
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function safeDown()
  25. {
  26. return false;
  27. }
  28. }