| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace app\migrations;
- use yii\db\Migration;
- /**
- * Class M240806032700UpdateQimallMenu
- */
- class M240806032700UpdateQimallMenu extends Migration
- {
- /**
- * {@inheritdoc}
- */
- public function safeUp()
- {
- // 先验证 qimall_menu 和 title 字段是否存在
- $checkSql = "
- SELECT
- (SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = 'qimall_menu') AS table_exists,
- (SELECT COUNT(*) FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'qimall_menu' AND column_name = 'title') AS column_exists
- ";
- try {
- $result = $this->db->createCommand($checkSql)->queryOne();
- if ($result['table_exists'] > 0 && $result['column_exists'] > 0) {
- $sql = "DELETE FROM `qimall_menu` WHERE `title` = '打印日志';";
- $this->execute($sql);
- } else {
- echo "Table or column does not exist.\n";
- }
- } catch (\Exception $e) {
- echo "Failed to delete record: " . $e->getMessage() . "\n";
- return true;
- }
- }
- /**
- * {@inheritdoc}
- */
- public function safeDown()
- {
- echo "M240806032700UpdateQimallMenu cannot be reverted.\n";
- return false;
- }
- }
|