M250516155535AddLinkCategory.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace app\migrations;
  3. use yii\db\Migration;
  4. /**
  5. * Class M250516155535AddLinkCategory
  6. */
  7. class M250516155535AddLinkCategory extends Migration
  8. {
  9. /**
  10. * {@inheritdoc}
  11. */
  12. public function safeUp()
  13. {
  14. try {
  15. $exists = $this->db->createCommand("
  16. SELECT 1 FROM `qimall_link_category` WHERE `title` = '小白优选' LIMIT 1
  17. ")->queryScalar();
  18. if (!$exists) {
  19. $this->db->createCommand("
  20. INSERT INTO `qimall_link_category` (`name`, `title`, `pid`, `is_list`, `remark`, `status`, `created_at`, `updated_at`)
  21. VALUES ('store_goods', '小白优选', 19, 1, '', 1, 1747366655, 1747366655)
  22. ")->execute();
  23. }
  24. } catch (\Exception $e) {
  25. echo "Error: " . $e->getMessage();
  26. }
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function safeDown()
  32. {
  33. echo "M250516155535AddLinkCategory cannot be reverted.\n";
  34. return false;
  35. }
  36. }