-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #324 from nabeelio/265-editable-pilot-id
Backend changes separating id from pilot_id
- Loading branch information
Showing
36 changed files
with
522 additions
and
59 deletions.
There are no files selected for viewing
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
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
66 changes: 66 additions & 0 deletions
66
app/Database/migrations/2019_07_16_141152_users_add_pilot_id.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,66 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class UsersAddPilotId extends Migration | ||
{ | ||
/** | ||
* Kinda of gross operations to change the pilot ID column | ||
* 1. Add an `pilot_id` column, which will get populated with the current ID | ||
* 2. Drop the `id` column, and then recreate it as a string field | ||
* 3. Iterate through all of the users and set their `id` to the `pilot_id` | ||
* 4. Change the other tables column types that reference `user_id` | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::table('users', function (Blueprint $table) { | ||
$table->unsignedBigInteger('pilot_id') | ||
->after('id') | ||
->unique() | ||
->nullable() | ||
->index('users_pilot_id'); | ||
}); | ||
|
||
// Migrate the current pilot IDs | ||
DB::update('UPDATE `users` SET `pilot_id`=`id`'); | ||
|
||
// Drop the old ID column and add a new one | ||
/*Schema::table('users', function (Blueprint $table) { | ||
$table->dropPrimary('users_id_primary'); | ||
$table->dropColumn('id'); | ||
$table->string('id', Model::ID_MAX_LENGTH)->primary(); | ||
}); | ||
// Update the users to use the `pilot_id` (so we don't need to migrate data from other tables) | ||
$users = DB::table('users')->get(['id']); | ||
foreach ($users as $user) { | ||
$user->id = $user->pilot_id; | ||
$user->save(); | ||
}*/ | ||
|
||
// role_user | ||
// permission_user | ||
// sessions | ||
// pireps | ||
// bids | ||
// news | ||
// user_awards | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::table('users', function (Blueprint $table) { | ||
$table->dropColumn('pilot_id'); | ||
}); | ||
} | ||
} |
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
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,9 @@ | ||
<?php | ||
|
||
namespace App\Exceptions; | ||
|
||
class UserPilotIdExists extends InternalError | ||
{ | ||
public const FIELD = 'pilot_id'; | ||
public const MESSAGE = 'A user with this pilot ID already exists'; | ||
} |
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
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
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
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
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
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
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
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
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
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
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,26 @@ | ||
<?php | ||
|
||
namespace App\Models\Observers; | ||
|
||
use App\Models\User; | ||
use App\Services\UserService; | ||
|
||
class UserObserver | ||
{ | ||
private $userSvc; | ||
|
||
public function __construct(UserService $userSvc) | ||
{ | ||
$this->userSvc = $userSvc; | ||
} | ||
|
||
/** | ||
* After a user has been created, do some stuff | ||
* | ||
* @param User $user | ||
*/ | ||
public function created(User $user): void | ||
{ | ||
$this->userSvc->findAndSetPilotId($user); | ||
} | ||
} |
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
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
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
Oops, something went wrong.