Skip to content

Commit d1c21a2

Browse files
[13.x] Add an optional migration for oauth_clients table to the upgrade guide (#1843)
* add migrations to the upgrade guide * wip * Update UPGRADE.md --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 15b8de5 commit d1c21a2

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

UPGRADE.md

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,42 @@ Passport::$validateKeyPermissions = false;
126126

127127
PR: https://github.com/laravel/passport/pull/1744, https://github.com/laravel/passport/pull/1797
128128

129-
Passport's `oauth_clients` table has been changed in several ways:
130129

131-
- The `user_id` column has been replaced by the `owner_type` and `owner_id` columns.
132-
- The `redirect` column has been replaced by the `redirect_uris` column. The new column needs to store an array of URLs.
133-
- The `personal_access_client` and `password_client` columns have been replaced by the `grant_types` column. The new column needs to store an array of OAuth 2 grant types.
130+
Passport 13 introduces a new schema for the `oauth_clients` table. However, These changes are **fully backward compatible**, and **no action is required** on your part.
134131

135-
Passport's `Laravel\Passport\Database\Factories\ClientFactory` factory class has been updated to reflect the changes to this table. If you do not want to make these changes to your application's `oauth_clients` table, you may use the [old Client factory class](https://github.com/laravel/passport/blob/12.x/database/factories/ClientFactory.php).
132+
For reference, here are the changes on the `oauth_clients` table:
133+
134+
- The `user_id` column has been replaced with `owner_type` and `owner_id` columns.
135+
- The `redirect` column has been replaced with `redirect_uris` column, which now stores an array of URIs.
136+
- The `personal_access_client` and `password_client` columns have been replaced with `grant_types` column, which stores an array of supported OAuth 2 grant types.
137+
138+
If you prefer to use the new structure, you may create a migration to apply the changes:
139+
140+
```php
141+
Schema::table('oauth_clients', function (Blueprint $table) {
142+
$table->nullableMorphs('owner')->after('user_id');
143+
144+
$table->after('provider', function (Blueprint $table) {
145+
$table->text('redirect_uris');
146+
$table->text('grant_types');
147+
});
148+
});
149+
150+
foreach (Passport::client()->cursor() as $client) {
151+
Model::withoutTimestamps(fn () => $client->forceFill([
152+
'owner_id' => $client->user_id,
153+
'owner_type' => $client->user_id ? config('auth.providers.'.$client->provider.'.model') : null,
154+
'redirect_uris' => $client->redirect_uris,
155+
'grant_types' => $client->grant_types,
156+
])->save());
157+
}
158+
159+
Schema::table('oauth_clients', function (Blueprint $table) {
160+
$table->dropColumn(['user_id', 'redirect', 'personal_access_client', 'password_client']);
161+
});
162+
```
163+
164+
Additionally, Passport's `Laravel\Passport\Database\Factories\ClientFactory` factory class has been updated to reflect the changes to this table. If you do not want to make these changes to your application's `oauth_clients` table, you may use the [old Client factory class](https://github.com/laravel/passport/blob/12.x/database/factories/ClientFactory.php).
136165

137166
## Upgrading To 12.0 From 11.x
138167

0 commit comments

Comments
 (0)