From 53073df84b830f78c8cc54d0df099bfa3cb42d08 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Mon, 24 Jun 2024 17:56:29 +0330 Subject: [PATCH 1/4] refactor migrations --- ...01_000001_create_oauth_auth_codes_table.php | 16 +++++++++++++--- ...000002_create_oauth_access_tokens_table.php | 18 ++++++++++++++---- ...00003_create_oauth_refresh_tokens_table.php | 14 ++++++++++++-- ...06_01_000004_create_oauth_clients_table.php | 16 +++++++++++++--- src/Console/InstallCommand.php | 6 +++--- 5 files changed, 55 insertions(+), 15 deletions(-) diff --git a/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php b/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php index 7b93b406a..9d669fa3f 100644 --- a/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php +++ b/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php @@ -12,9 +12,9 @@ public function up(): void { Schema::create('oauth_auth_codes', function (Blueprint $table) { - $table->string('id', 100)->primary(); - $table->unsignedBigInteger('user_id')->index(); - $table->unsignedBigInteger('client_id'); + $table->char('id', 80)->primary(); + $table->foreignId('user_id'); + $table->foreignId('client_id'); $table->text('scopes')->nullable(); $table->boolean('revoked'); $table->dateTime('expires_at')->nullable(); @@ -28,4 +28,14 @@ public function down(): void { Schema::dropIfExists('oauth_auth_codes'); } + + /** + * Get the migration connection name. + * + * @return string|null + */ + public function getConnection() + { + return $this->connection ?? config('passport.connection'); + } }; diff --git a/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php b/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php index 598798eef..34c058a56 100644 --- a/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php +++ b/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php @@ -12,11 +12,11 @@ public function up(): void { Schema::create('oauth_access_tokens', function (Blueprint $table) { - $table->string('id', 100)->primary(); - $table->unsignedBigInteger('user_id')->nullable()->index(); - $table->unsignedBigInteger('client_id'); + $table->char('id', 80)->primary(); + $table->foreignId('user_id')->nullable()->index(); + $table->foreignId('client_id'); $table->string('name')->nullable(); - $table->text('scopes')->nullable(); + $table->text('scopes'); $table->boolean('revoked'); $table->timestamps(); $table->dateTime('expires_at')->nullable(); @@ -30,4 +30,14 @@ public function down(): void { Schema::dropIfExists('oauth_access_tokens'); } + + /** + * Get the migration connection name. + * + * @return string|null + */ + public function getConnection() + { + return $this->connection ?? config('passport.connection'); + } }; diff --git a/database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php b/database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php index b007904ce..c94c91abd 100644 --- a/database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php +++ b/database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php @@ -12,8 +12,8 @@ public function up(): void { Schema::create('oauth_refresh_tokens', function (Blueprint $table) { - $table->string('id', 100)->primary(); - $table->string('access_token_id', 100)->index(); + $table->char('id', 80)->primary(); + $table->char('access_token_id', 80)->index(); $table->boolean('revoked'); $table->dateTime('expires_at')->nullable(); }); @@ -26,4 +26,14 @@ public function down(): void { Schema::dropIfExists('oauth_refresh_tokens'); } + + /** + * Get the migration connection name. + * + * @return string|null + */ + public function getConnection() + { + return $this->connection ?? config('passport.connection'); + } }; diff --git a/database/migrations/2016_06_01_000004_create_oauth_clients_table.php b/database/migrations/2016_06_01_000004_create_oauth_clients_table.php index 776ccfab2..502eb2aae 100644 --- a/database/migrations/2016_06_01_000004_create_oauth_clients_table.php +++ b/database/migrations/2016_06_01_000004_create_oauth_clients_table.php @@ -12,12 +12,12 @@ public function up(): void { Schema::create('oauth_clients', function (Blueprint $table) { - $table->bigIncrements('id'); - $table->unsignedBigInteger('user_id')->nullable()->index(); + $table->id(); + $table->foreignId('user_id')->nullable()->index(); $table->string('name'); $table->string('secret', 100)->nullable(); $table->string('provider')->nullable(); - $table->text('redirect'); + $table->text('redirect')->nullable(); $table->boolean('personal_access_client'); $table->boolean('password_client'); $table->boolean('revoked'); @@ -32,4 +32,14 @@ public function down(): void { Schema::dropIfExists('oauth_clients'); } + + /** + * Get the migration connection name. + * + * @return string|null + */ + public function getConnection() + { + return $this->connection ?? config('passport.connection'); + } }; diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php index a9ffb38a6..87bd95f4a 100644 --- a/src/Console/InstallCommand.php +++ b/src/Console/InstallCommand.php @@ -66,9 +66,9 @@ protected function configureUuids() Passport::setClientUuids(true); $this->replaceInFile(config_path('passport.php'), '\'client_uuids\' => false', '\'client_uuids\' => true'); - $this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_auth_codes_table.php'), '$table->unsignedBigInteger(\'client_id\');', '$table->uuid(\'client_id\');'); - $this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_access_tokens_table.php'), '$table->unsignedBigInteger(\'client_id\');', '$table->uuid(\'client_id\');'); - $this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_clients_table.php'), '$table->bigIncrements(\'id\');', '$table->uuid(\'id\')->primary();'); + $this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_auth_codes_table.php'), '$table->foreignId(\'client_id\');', '$table->foreignUuid(\'client_id\');'); + $this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_access_tokens_table.php'), '$table->foreignId(\'client_id\');', '$table->foreignUuid(\'client_id\');'); + $this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_clients_table.php'), '$table->id();', '$table->uuid(\'id\')->primary();'); } /** From 88a7c49c89d10113f114e7d385d566842cfb419c Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Mon, 24 Jun 2024 20:06:54 +0330 Subject: [PATCH 2/4] revert nullable scopes column --- .../2016_06_01_000002_create_oauth_access_tokens_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php b/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php index 34c058a56..97f78510d 100644 --- a/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php +++ b/database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php @@ -16,7 +16,7 @@ public function up(): void $table->foreignId('user_id')->nullable()->index(); $table->foreignId('client_id'); $table->string('name')->nullable(); - $table->text('scopes'); + $table->text('scopes')->nullable(); $table->boolean('revoked'); $table->timestamps(); $table->dateTime('expires_at')->nullable(); From 0440346524e8e5310b18f9ccd9b18c2ece19f694 Mon Sep 17 00:00:00 2001 From: Hafez Divandari Date: Mon, 24 Jun 2024 20:11:19 +0330 Subject: [PATCH 3/4] revert nullable redirect column --- .../migrations/2016_06_01_000004_create_oauth_clients_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/2016_06_01_000004_create_oauth_clients_table.php b/database/migrations/2016_06_01_000004_create_oauth_clients_table.php index 502eb2aae..1ed6feede 100644 --- a/database/migrations/2016_06_01_000004_create_oauth_clients_table.php +++ b/database/migrations/2016_06_01_000004_create_oauth_clients_table.php @@ -17,7 +17,7 @@ public function up(): void $table->string('name'); $table->string('secret', 100)->nullable(); $table->string('provider')->nullable(); - $table->text('redirect')->nullable(); + $table->text('redirect'); $table->boolean('personal_access_client'); $table->boolean('password_client'); $table->boolean('revoked'); From 423a4ec69337303a91ec372fa0681a9156c77dc0 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 24 Jun 2024 22:40:29 +0200 Subject: [PATCH 4/4] Update 2016_06_01_000001_create_oauth_auth_codes_table.php --- .../2016_06_01_000001_create_oauth_auth_codes_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php b/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php index 9d669fa3f..9a50ded40 100644 --- a/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php +++ b/database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php @@ -13,7 +13,7 @@ public function up(): void { Schema::create('oauth_auth_codes', function (Blueprint $table) { $table->char('id', 80)->primary(); - $table->foreignId('user_id'); + $table->foreignId('user_id')->index(); $table->foreignId('client_id'); $table->text('scopes')->nullable(); $table->boolean('revoked');