| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- namespace app\migrations;
- use yii\db\Migration;
- /**
- * Class M250416105120UpdateAttachment
- */
- class M250416105120UpdateAttachment extends Migration
- {
- /**
- * {@inheritdoc}
- */
- public function safeUp()
- {
- try {
- // 1. 添加联合索引
- $sql = <<<SQL
- ALTER TABLE `qimall_attachment`
- ADD INDEX `idx_mall_delete_recycle_url` (`mall_id`, `is_delete`, `is_recycle`, `url`(255));
- SQL;
- $this->execute($sql);
-
- // 2. 删除冗余索引
- $sql = <<<SQL
- DROP INDEX `idx_mall_id` ON `qimall_attachment`;
- DROP INDEX `idx_is_delete` ON `qimall_attachment`;
- SQL;
- $this->execute($sql);
-
- } catch (\Exception $e) {
- // 静默处理异常
- }
- }
- /**
- * {@inheritdoc}
- */
- public function safeDown()
- {
- echo "M250416105120UpdateAttachment cannot be reverted.\n";
- return false;
- }
- }
|