Changeset View
Changeset View
Standalone View
Standalone View
src/database/migrations/2021_04_28_090011_create_oauth_tables.php
- This file was added.
<?php | |||||
use Illuminate\Database\Migrations\Migration; | |||||
use Illuminate\Database\Schema\Blueprint; | |||||
use Illuminate\Support\Facades\Schema; | |||||
// phpcs:ignore | |||||
class CreateOauthTables extends Migration | |||||
{ | |||||
/** | |||||
* Run the migrations. | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function up() | |||||
{ | |||||
Schema::create('oauth_clients', function (Blueprint $table) { | |||||
$table->bigIncrements('id'); | |||||
$table->bigInteger('user_id')->nullable()->index(); | |||||
$table->string('name'); | |||||
$table->string('secret', 100)->nullable(); | |||||
$table->string('provider')->nullable(); | |||||
$table->text('redirect'); | |||||
$table->boolean('personal_access_client'); | |||||
$table->boolean('password_client'); | |||||
$table->boolean('revoked'); | |||||
$table->timestamps(); | |||||
$table->foreign('user_id') | |||||
->references('id')->on('users') | |||||
->onDelete('cascade') | |||||
->onUpdate('cascade'); | |||||
}); | |||||
Schema::create('oauth_personal_access_clients', function (Blueprint $table) { | |||||
$table->bigIncrements('id'); | |||||
$table->bigInteger('client_id'); | |||||
$table->timestamps(); | |||||
}); | |||||
Schema::create('oauth_auth_codes', function (Blueprint $table) { | |||||
$table->string('id', 100)->primary(); | |||||
$table->bigInteger('user_id')->index(); | |||||
$table->bigInteger('client_id'); | |||||
$table->text('scopes')->nullable(); | |||||
$table->boolean('revoked'); | |||||
$table->dateTime('expires_at')->nullable(); | |||||
$table->foreign('user_id') | |||||
->references('id')->on('users') | |||||
->onDelete('cascade') | |||||
->onUpdate('cascade'); | |||||
}); | |||||
Schema::create('oauth_access_tokens', function (Blueprint $table) { | |||||
$table->string('id', 100)->primary(); | |||||
$table->bigInteger('user_id')->nullable()->index(); | |||||
$table->bigInteger('client_id'); | |||||
$table->string('name')->nullable(); | |||||
machniak: Shouldn't `client_id` be a foreign key? Here and above. | |||||
Done Inline ActionsIt's a reference to the other table, but it IMO doesn't require the foreign key constraint (which afaik forces the creation of an index). I don't think we frequently access this link, and the lifetime of the token is not bound to the lifetime of the client. mollekopf: It's a reference to the other table, but it IMO doesn't require the foreign key constraint… | |||||
$table->text('scopes')->nullable(); | |||||
$table->boolean('revoked'); | |||||
$table->timestamps(); | |||||
$table->dateTime('expires_at')->nullable(); | |||||
$table->foreign('user_id') | |||||
->references('id')->on('users') | |||||
->onDelete('cascade') | |||||
->onUpdate('cascade'); | |||||
}); | |||||
Schema::create('oauth_refresh_tokens', function (Blueprint $table) { | |||||
$table->string('id', 100)->primary(); | |||||
$table->string('access_token_id', 100)->index(); | |||||
$table->boolean('revoked'); | |||||
Done Inline ActionsShouldn't access_token_id be a foreign key? machniak: Shouldn't `access_token_id` be a foreign key? | |||||
Done Inline ActionsCould make sense, but I'm not sure it's necessary either as all tokens are regularly cleaned up individually (So the ON DELETE CASCADE doesn't seem required). mollekopf: Could make sense, but I'm not sure it's necessary either as all tokens are regularly cleaned up… | |||||
$table->dateTime('expires_at')->nullable(); | |||||
}); | |||||
} | |||||
/** | |||||
* Reverse the migrations. | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function down() | |||||
{ | |||||
Schema::dropIfExists('oauth_auth_codes'); | |||||
Schema::dropIfExists('oauth_refresh_tokens'); | |||||
Schema::dropIfExists('oauth_access_tokens'); | |||||
Schema::dropIfExists('oauth_personal_access_clients'); | |||||
Schema::dropIfExists('oauth_clients'); | |||||
} | |||||
} |
Shouldn't client_id be a foreign key? Here and above.