Skip to content

Commit 537e80d

Browse files
authored
use numeric ids for users (#22)
* use numeric ids for users * Apply fixes from StyleCI (#21)
1 parent af9bba5 commit 537e80d

File tree

11 files changed

+11
-104
lines changed

11 files changed

+11
-104
lines changed

database/migrations/2014_10_12_000000_create_users_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class CreateUsersTable extends Migration
1414
public function up()
1515
{
1616
Schema::create('users', function (Blueprint $table) {
17-
$table->uuid('id')->primary();
17+
$table->id();
1818
$table->string('name');
1919
$table->string('email')->unique();
2020
$table->timestamp('email_verified_at')->nullable();

database/migrations/2020_05_21_100000_create_teams_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function up()
1515
{
1616
Schema::create('teams', function (Blueprint $table) {
1717
$table->uuid('id')->primary();
18-
$table->uuid('user_id')->index();
18+
$table->foreignId('user_id')->index();
1919
$table->string('name');
2020
$table->boolean('personal_team');
2121
$table->timestamps();

database/migrations/2020_05_21_200000_create_team_user_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function up()
1616
Schema::create('team_user', function (Blueprint $table) {
1717
$table->id();
1818
$table->uuid('team_id');
19-
$table->uuid('user_id');
19+
$table->foreignId('user_id');
2020
$table->string('role')->nullable();
2121
$table->timestamps();
2222

src/Console/InstallCommand.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,6 @@ protected function configureSession()
103103
$this->replaceInFile("'SESSION_DRIVER', 'file'", "'SESSION_DRIVER', 'database'", config_path('session.php'));
104104
$this->replaceInFile('SESSION_DRIVER=file', 'SESSION_DRIVER=database', base_path('.env'));
105105
$this->replaceInFile('SESSION_DRIVER=file', 'SESSION_DRIVER=database', base_path('.env.example'));
106-
107-
foreach ((new Filesystem)->files(database_path('migrations')) as $file) {
108-
if (Str::contains($file->getRealPath(), 'create_sessions_table')) {
109-
$this->replaceInFile("foreignId('user_id')", "uuid('user_id')", $file->getRealPath());
110-
111-
break;
112-
}
113-
}
114106
}
115107

116108
/**
@@ -132,8 +124,6 @@ protected function installLivewireStack()
132124
$this->output->write($output);
133125
});
134126

135-
$this->replaceInFile('morphs', 'uuidMorphs', database_path('migrations/2019_12_14_000001_create_personal_access_tokens_table.php'));
136-
137127
// Update Configuration...
138128
$this->replaceInFile('inertia', 'livewire', config_path('jetstream.php'));
139129
$this->replaceInFile("'guard' => 'web'", "'guard' => 'sanctum'", config_path('auth.php'));
@@ -279,8 +269,6 @@ protected function installInertiaStack()
279269
$this->output->write($output);
280270
});
281271

282-
$this->replaceInFile('morphs', 'uuidMorphs', database_path('migrations/2019_12_14_000001_create_personal_access_tokens_table.php'));
283-
284272
// Update Configuration...
285273
$this->replaceInFile("'guard' => 'web'", "'guard' => 'sanctum'", config_path('auth.php'));
286274

src/HasTeams.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function personalTeam()
8080
*/
8181
public function ownsTeam($team)
8282
{
83-
return $this->id === $team->user_id;
83+
return (int) $this->id === (int) $team->user_id;
8484
}
8585

8686
/**

src/Http/Controllers/Inertia/TeamMemberController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function store(Request $request, $teamId)
3737
*
3838
* @param \Illuminate\Http\Request $request
3939
* @param string $teamId
40-
* @param string $userId
40+
* @param int $userId
4141
* @return \Illuminate\Http\RedirectResponse
4242
*/
4343
public function update(Request $request, $teamId, $userId)
@@ -57,7 +57,7 @@ public function update(Request $request, $teamId, $userId)
5757
*
5858
* @param \Illuminate\Http\Request $request
5959
* @param string $teamId
60-
* @param string $userId
60+
* @param int $userId
6161
* @return \Illuminate\Http\RedirectResponse
6262
*/
6363
public function destroy(Request $request, $teamId, $userId)

src/Http/Livewire/TeamMemberManager.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class TeamMemberManager extends Component
5656
/**
5757
* The ID of the team member being removed.
5858
*
59-
* @var string|null
59+
* @var int|null
6060
*/
6161
public $teamMemberIdBeingRemoved = null;
6262

@@ -111,7 +111,7 @@ public function addTeamMember(AddsTeamMembers $adder)
111111
/**
112112
* Allow the given user's role to be managed.
113113
*
114-
* @param string $userId
114+
* @param int $userId
115115
* @return void
116116
*/
117117
public function manageRole($userId)
@@ -173,7 +173,7 @@ public function leaveTeam(RemoveTeamMember $remover)
173173
/**
174174
* Confirm that the given team member should be removed.
175175
*
176-
* @param string $userId
176+
* @param int $userId
177177
* @return void
178178
*/
179179
public function confirmTeamMemberRemoval($userId)

src/Jetstream.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ public static function hasTeamFeatures()
160160
/**
161161
* Find a user instance by the given ID.
162162
*
163-
* @param string $id
163+
* @param int $id
164164
*/
165-
public static function findUserByIdOrFail(string $id)
165+
public static function findUserByIdOrFail($id)
166166
{
167167
return static::newUserModel()->where('id', $id)->firstOrFail();
168168
}

stubs/app/Models/User.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Illuminate\Database\Eloquent\Factories\HasFactory;
66
use Illuminate\Foundation\Auth\User as Authenticatable;
77
use Illuminate\Notifications\Notifiable;
8-
use Illuminate\Support\Str;
98
use Laravel\Fortify\TwoFactorAuthenticatable;
109
use Laravel\Jetstream\HasProfilePhoto;
1110
use Laravel\Sanctum\HasApiTokens;
@@ -18,20 +17,6 @@ class User extends Authenticatable
1817
use Notifiable;
1918
use TwoFactorAuthenticatable;
2019

21-
/**
22-
* The "type" of the primary key ID.
23-
*
24-
* @var string
25-
*/
26-
protected $keyType = 'string';
27-
28-
/**
29-
* Indicates if the IDs are auto-incrementing.
30-
*
31-
* @var bool
32-
*/
33-
public $incrementing = false;
34-
3520
/**
3621
* The attributes that are mass assignable.
3722
*
@@ -72,16 +57,4 @@ class User extends Authenticatable
7257
protected $appends = [
7358
'profile_photo_url',
7459
];
75-
76-
/**
77-
* Handle the model "booted" event.
78-
*
79-
* @return void
80-
*/
81-
public static function booted()
82-
{
83-
static::creating(function ($model) {
84-
$model->id = $model->id ?: (string) Str::orderedUuid();
85-
});
86-
}
8760
}

stubs/app/Models/UserWithTeams.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Illuminate\Database\Eloquent\Factories\HasFactory;
66
use Illuminate\Foundation\Auth\User as Authenticatable;
77
use Illuminate\Notifications\Notifiable;
8-
use Illuminate\Support\Str;
98
use Laravel\Fortify\TwoFactorAuthenticatable;
109
use Laravel\Jetstream\HasProfilePhoto;
1110
use Laravel\Jetstream\HasTeams;
@@ -20,20 +19,6 @@ class User extends Authenticatable
2019
use Notifiable;
2120
use TwoFactorAuthenticatable;
2221

23-
/**
24-
* The "type" of the primary key ID.
25-
*
26-
* @var string
27-
*/
28-
protected $keyType = 'string';
29-
30-
/**
31-
* Indicates if the IDs are auto-incrementing.
32-
*
33-
* @var bool
34-
*/
35-
public $incrementing = false;
36-
3722
/**
3823
* The attributes that are mass assignable.
3924
*
@@ -72,16 +57,4 @@ class User extends Authenticatable
7257
protected $appends = [
7358
'profile_photo_url',
7459
];
75-
76-
/**
77-
* Handle the model "booted" event.
78-
*
79-
* @return void
80-
*/
81-
public static function booted()
82-
{
83-
static::creating(function ($model) {
84-
$model->id = $model->id ?: (string) Str::orderedUuid();
85-
});
86-
}
8760
}

0 commit comments

Comments
 (0)