-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change column type to unsigned big integer for ID in users table
- Loading branch information
1 parent
f189d51
commit 24101f8
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...ns/2023_10_26_220756_change_column_type_to_unsigned_big_integer_for_id_in_users_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
private function dropExistingForeignKeys(): void | ||
{ | ||
Schema::table('activities', fn (Blueprint $table) => $table->dropForeign(['user_id'])); | ||
Schema::table('ideas', fn (Blueprint $table) => $table->dropForeign(['user_id'])); | ||
Schema::table('login_attempts', fn (Blueprint $table) => $table->dropForeign(['user_id'])); | ||
Schema::table('user_space', fn (Blueprint $table) => $table->dropForeign(['user_id'])); | ||
Schema::table('widgets', fn (Blueprint $table) => $table->dropForeign(['user_id'])); | ||
} | ||
|
||
private function reAddForeignKeys(): void | ||
{ | ||
Schema::table('activities', fn (Blueprint $table) => $table->foreign('user_id')->references('id')->on('users')); | ||
Schema::table('ideas', fn (Blueprint $table) => $table->foreign('user_id')->references('id')->on('users')); | ||
Schema::table('login_attempts', fn (Blueprint $table) => $table->foreign('user_id')->references('id')->on('users')); | ||
Schema::table('user_space', fn (Blueprint $table) => $table->foreign('user_id')->references('id')->on('users')); | ||
Schema::table('widgets', fn (Blueprint $table) => $table->foreign('user_id')->references('id')->on('users')); | ||
} | ||
|
||
public function up(): void | ||
{ | ||
$this->dropExistingForeignKeys(); | ||
|
||
Schema::table('users', fn (Blueprint $table) => $table->id()->change()); | ||
|
||
Schema::table('activities', fn (Blueprint $table) => $table->foreignId('user_id')->change()); | ||
Schema::table('ideas', fn (Blueprint $table) => $table->foreignId('user_id')->change()); | ||
Schema::table('login_attempts', fn (Blueprint $table) => $table->foreignId('user_id')->change()); | ||
Schema::table('user_space', fn (Blueprint $table) => $table->foreignId('user_id')->change()); | ||
Schema::table('widgets', fn (Blueprint $table) => $table->foreignId('user_id')->change()); | ||
|
||
$this->reAddForeignKeys(); | ||
} | ||
|
||
public function down(): void | ||
{ | ||
$this->dropExistingForeignKeys(); | ||
|
||
Schema::table('users', fn (Blueprint $table) => $table->increments('id')->change()); | ||
|
||
Schema::table('activities', fn (Blueprint $table) => $table->unsignedInteger('user_id')->change()); | ||
Schema::table('ideas', fn (Blueprint $table) => $table->unsignedInteger('user_id')->change()); | ||
Schema::table('login_attempts', fn (Blueprint $table) => $table->unsignedInteger('user_id')->change()); | ||
Schema::table('user_space', fn (Blueprint $table) => $table->unsignedInteger('user_id')->change()); | ||
Schema::table('widgets', fn (Blueprint $table) => $table->unsignedInteger('user_id')->change()); | ||
|
||
$this->reAddForeignKeys(); | ||
} | ||
}; |