2023063000-add_user_is_inactive.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. declare(strict_types=1);
  3. use App\Interfaces\MigrationInterface;
  4. use App\Services\DB;
  5. return new class() implements MigrationInterface {
  6. public function up(): int
  7. {
  8. DB::getPdo()->exec("
  9. ALTER TABLE user DROP COLUMN IF EXISTS `t`;
  10. ALTER TABLE user ADD COLUMN IF NOT EXISTS `is_inactive` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否处于闲置状态';
  11. ALTER TABLE user ADD COLUMN IF NOT EXISTS `last_use_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '最后使用时间';
  12. ALTER TABLE user ADD COLUMN IF NOT EXISTS `last_login_time` int(11) unsigned DEFAULT 0 COMMENT '最后登录时间';
  13. ALTER TABLE user ADD KEY IF NOT EXISTS `is_inactive` (`is_inactive`);
  14. ");
  15. return 2023063000;
  16. }
  17. public function down(): int
  18. {
  19. DB::getPdo()->exec("
  20. ALTER TABLE user ADD COLUMN IF NOT EXISTS `t` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '最后使用时间';
  21. ALTER TABLE user DROP COLUMN IF EXISTS `is_inactive`;
  22. ALTER TABLE user DROP COLUMN IF EXISTS `last_use_time`;
  23. ALTER TABLE user DROP COLUMN IF EXISTS `last_login_time`;
  24. ALTER TABLE user DROP KEY IF EXISTS `is_inactive`;
  25. ");
  26. return 2023061800;
  27. }
  28. };