From 845dcfee38ed908f22f1a682f2e4d3c5c55819f0 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 6 Jan 2025 15:22:06 +0900 Subject: [PATCH 1/2] Add `osu_logins` migration For use in https://github.com/ppy/osu-server-spectator/pull/253. --- .../2025_01_06_000000_create_osu_logins.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 database/migrations/2025_01_06_000000_create_osu_logins.php diff --git a/database/migrations/2025_01_06_000000_create_osu_logins.php b/database/migrations/2025_01_06_000000_create_osu_logins.php new file mode 100644 index 00000000000..ff42c496bc7 --- /dev/null +++ b/database/migrations/2025_01_06_000000_create_osu_logins.php @@ -0,0 +1,36 @@ +. Licensed under the GNU Affero General Public License v3.0. +// See the LICENCE file in the repository root for full licence text. + +declare(strict_types=1); + +use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Schema; + +return new class extends Migration +{ + public function up(): void + { + // This is a legacy table. Migration is added for external projects' sake. + if (Schema::hasTable('osu_logins')) { + return; + } + + Schema::create('osu_logins', function (Blueprint $table) { + $table->unsignedInteger('user_id')->default(0); + $table->string('ip', 100)->default(''); + $table->timestamp('date')->useCurrent(); + + $table->index('user_id'); + $table->index('date'); + $table->index('ip'); + }); + } + + public function down(): void + { + Schema::dropIfExists('teams'); + } +}; From 1cae1e27e78e649d122f97e354afe9dd0a9ebcb8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 6 Jan 2025 15:45:03 +0900 Subject: [PATCH 2/2] Add explicit index names and fix `down()` function Co-authored-by: Edho Arief --- .../migrations/2025_01_06_000000_create_osu_logins.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/database/migrations/2025_01_06_000000_create_osu_logins.php b/database/migrations/2025_01_06_000000_create_osu_logins.php index ff42c496bc7..6d0840afa43 100644 --- a/database/migrations/2025_01_06_000000_create_osu_logins.php +++ b/database/migrations/2025_01_06_000000_create_osu_logins.php @@ -23,14 +23,14 @@ public function up(): void $table->string('ip', 100)->default(''); $table->timestamp('date')->useCurrent(); - $table->index('user_id'); - $table->index('date'); - $table->index('ip'); + $table->index('user_id', 'user_id'); + $table->index('date', 'date'); + $table->index('ip', 'ip'); }); } public function down(): void { - Schema::dropIfExists('teams'); + Schema::dropIfExists('osu_logins'); } };