From b16593c16248b5ebee99bebc00a9d91f9db8e131 Mon Sep 17 00:00:00 2001 From: Shaggy84675 Date: Sat, 2 Aug 2025 17:21:32 +0200 Subject: [PATCH] Fix issues with unique keys Signed-off-by: Shaggy84675 --- ...4_04_15_222616_modify_game_files_table.php | 19 +++++++++++++++++++ ...26_add_additional_column_to_game_files.php | 6 +++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/dist/database/migrations/2024_04_15_222616_modify_game_files_table.php b/dist/database/migrations/2024_04_15_222616_modify_game_files_table.php index f2ad1ab..c649f48 100644 --- a/dist/database/migrations/2024_04_15_222616_modify_game_files_table.php +++ b/dist/database/migrations/2024_04_15_222616_modify_game_files_table.php @@ -11,8 +11,19 @@ */ public function up(): void { + if (Schema::hasIndex('game_files', ['name', 'hash', 'version'])) { + Schema::table('game_files', function (Blueprint $table) { + $table->dropUnique(['name', 'hash', 'version']); + }); + } + //Schema doesn't support tinyint DB::statement("ALTER TABLE `game_files` CHANGE `version` `patchline` TINYINT UNSIGNED NOT NULL DEFAULT '1';"); + + + Schema::table('game_files', function (Blueprint $table) { + $table->unique(['name', 'hash', 'patchline']); + }); } /** @@ -20,11 +31,19 @@ public function up(): void */ public function down(): void { + if (Schema::hasIndex('game_files', ['name', 'hash', 'patchline'])) { + Schema::table('game_files', function (Blueprint $table) { + $table->dropUnique(['name', 'hash', 'patchline']); + }); + } Schema::table('game_files', function (Blueprint $table) { $table->integer('patchline')->default(1)->change(); }); Schema::table('game_files', function (Blueprint $table) { $table->renameColumn('patchline', 'version'); }); + Schema::table('game_files', function (Blueprint $table) { + $table->unique(['name', 'hash', 'version']); + }); } }; diff --git a/dist/database/migrations/2024_11_04_212126_add_additional_column_to_game_files.php b/dist/database/migrations/2024_11_04_212126_add_additional_column_to_game_files.php index fe45968..23a7607 100644 --- a/dist/database/migrations/2024_11_04_212126_add_additional_column_to_game_files.php +++ b/dist/database/migrations/2024_11_04_212126_add_additional_column_to_game_files.php @@ -14,11 +14,11 @@ public function up(): void //Schema doesn't support tinyint DB::statement("ALTER TABLE `game_files` ADD COLUMN `is_additional` TINYINT UNSIGNED NOT NULL DEFAULT '0' AFTER `action`;"); - if (Schema::hasIndex('game_files', ['name', 'hash', 'version'])) { + if (Schema::hasIndex('game_files', ['name', 'hash', 'patchline'])) { Schema::table('game_files', function (Blueprint $table) { - $table->dropUnique(['name', 'hash', 'version']); + $table->dropUnique(['name', 'hash', 'patchline']); }); - } + } Schema::table('game_files', function (Blueprint $table) { $table->renameColumn('name', 'filename');