2023032600-online_log_per_user-ip.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. $pdo = DB::getPdo();
  9. $pdo->exec('
  10. CREATE TABLE IF NOT EXISTS online_log (
  11. id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  12. user_id INT UNSIGNED NOT NULL,
  13. ip INET6 NOT NULL,
  14. node_id INT UNSIGNED NOT NULL,
  15. first_time INT UNSIGNED NOT NULL,
  16. last_time INT UNSIGNED NOT NULL,
  17. PRIMARY KEY (id),
  18. UNIQUE KEY (user_id, ip),
  19. KEY (last_time)
  20. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
  21. ');
  22. $pdo->exec('DROP TABLE IF EXISTS alive_ip');
  23. return 2023032600;
  24. }
  25. public function down(): int
  26. {
  27. $pdo = DB::getPdo();
  28. $pdo->exec('
  29. CREATE TABLE IF NOT EXISTS alive_ip (
  30. id BIGINT(20) NOT NULL AUTO_INCREMENT,
  31. nodeid INT(11) DEFAULT NULL,
  32. userid INT(11) DEFAULT NULL,
  33. ip VARCHAR(255) DEFAULT NULL,
  34. datetime BIGINT(20) DEFAULT NULL,
  35. PRIMARY KEY (id)
  36. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
  37. ');
  38. $pdo->exec('DROP TABLE IF EXISTS online_log');
  39. return 2023031701;
  40. }
  41. };