|
| 1 | +<?php |
| 2 | + |
| 3 | +use Illuminate\Database\Eloquent\Model; |
| 4 | +use Illuminate\Database\Migrations\Migration; |
| 5 | +use Illuminate\Database\Schema\Blueprint; |
| 6 | +use Illuminate\Support\Facades\Schema; |
| 7 | +use Laravel\Passport\Passport; |
| 8 | + |
| 9 | +return new class extends Migration { |
| 10 | + /** |
| 11 | + * Run the migrations. |
| 12 | + */ |
| 13 | + public function up(): void |
| 14 | + { |
| 15 | + // Copied from https://github.com/jaapredeker/passport/blob/021ab9adafbbaed1d600869ca891586ca99b2f49/UPGRADE.md#oauth-client-table-changes |
| 16 | + |
| 17 | + Schema::table('oauth_clients', function (Blueprint $table) { |
| 18 | + $table->nullableMorphs('owner', after: 'user_id'); |
| 19 | + |
| 20 | + $table->after('provider', function (Blueprint $table) { |
| 21 | + $table->text('redirect_uris')->nullable(); |
| 22 | + $table->text('grant_types')->nullable(); |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + foreach (Passport::client()->cursor() as $client) { |
| 27 | + if ($client->personal_access_client === true && $client->password_client === false) { |
| 28 | + $grantTypes = ['personal_access']; |
| 29 | + } else { |
| 30 | + $grantTypes = $client->grant_types; |
| 31 | + } |
| 32 | + Model::withoutTimestamps(fn () => $client->forceFill([ |
| 33 | + 'owner_id' => $client->user_id, |
| 34 | + 'owner_type' => $client->user_id |
| 35 | + ? config('auth.providers.' . ($client->provider ?: config('auth.guards.api.provider')) . '.model') |
| 36 | + : null, |
| 37 | + 'redirect_uris' => $client->redirect_uris, |
| 38 | + 'grant_types' => $grantTypes, |
| 39 | + ])->save()); |
| 40 | + } |
| 41 | + |
| 42 | + Schema::table('oauth_clients', function (Blueprint $table) { |
| 43 | + $table->dropColumn(['user_id', 'redirect', 'personal_access_client', 'password_client']); |
| 44 | + |
| 45 | + $table->text('redirect_uris')->nullable(false)->change(); |
| 46 | + $table->text('grant_types')->nullable(false)->change(); |
| 47 | + }); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Reverse the migrations. |
| 52 | + */ |
| 53 | + public function down(): void |
| 54 | + { |
| 55 | + // |
| 56 | + } |
| 57 | +}; |
0 commit comments