Skip to content

Commit 1e3fcd9

Browse files
[13.x] Refactor migrations (#1759)
* refactor migrations * revert nullable scopes column * revert nullable redirect column * Update 2016_06_01_000001_create_oauth_auth_codes_table.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 22b3861 commit 1e3fcd9

5 files changed

+53
-13
lines changed

database/migrations/2016_06_01_000001_create_oauth_auth_codes_table.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
public function up(): void
1313
{
1414
Schema::create('oauth_auth_codes', function (Blueprint $table) {
15-
$table->string('id', 100)->primary();
16-
$table->unsignedBigInteger('user_id')->index();
17-
$table->unsignedBigInteger('client_id');
15+
$table->char('id', 80)->primary();
16+
$table->foreignId('user_id')->index();
17+
$table->foreignId('client_id');
1818
$table->text('scopes')->nullable();
1919
$table->boolean('revoked');
2020
$table->dateTime('expires_at')->nullable();
@@ -28,4 +28,14 @@ public function down(): void
2828
{
2929
Schema::dropIfExists('oauth_auth_codes');
3030
}
31+
32+
/**
33+
* Get the migration connection name.
34+
*
35+
* @return string|null
36+
*/
37+
public function getConnection()
38+
{
39+
return $this->connection ?? config('passport.connection');
40+
}
3141
};

database/migrations/2016_06_01_000002_create_oauth_access_tokens_table.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
public function up(): void
1313
{
1414
Schema::create('oauth_access_tokens', function (Blueprint $table) {
15-
$table->string('id', 100)->primary();
16-
$table->unsignedBigInteger('user_id')->nullable()->index();
17-
$table->unsignedBigInteger('client_id');
15+
$table->char('id', 80)->primary();
16+
$table->foreignId('user_id')->nullable()->index();
17+
$table->foreignId('client_id');
1818
$table->string('name')->nullable();
1919
$table->text('scopes')->nullable();
2020
$table->boolean('revoked');
@@ -30,4 +30,14 @@ public function down(): void
3030
{
3131
Schema::dropIfExists('oauth_access_tokens');
3232
}
33+
34+
/**
35+
* Get the migration connection name.
36+
*
37+
* @return string|null
38+
*/
39+
public function getConnection()
40+
{
41+
return $this->connection ?? config('passport.connection');
42+
}
3343
};

database/migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
public function up(): void
1313
{
1414
Schema::create('oauth_refresh_tokens', function (Blueprint $table) {
15-
$table->string('id', 100)->primary();
16-
$table->string('access_token_id', 100)->index();
15+
$table->char('id', 80)->primary();
16+
$table->char('access_token_id', 80)->index();
1717
$table->boolean('revoked');
1818
$table->dateTime('expires_at')->nullable();
1919
});
@@ -26,4 +26,14 @@ public function down(): void
2626
{
2727
Schema::dropIfExists('oauth_refresh_tokens');
2828
}
29+
30+
/**
31+
* Get the migration connection name.
32+
*
33+
* @return string|null
34+
*/
35+
public function getConnection()
36+
{
37+
return $this->connection ?? config('passport.connection');
38+
}
2939
};

database/migrations/2016_06_01_000004_create_oauth_clients_table.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
public function up(): void
1313
{
1414
Schema::create('oauth_clients', function (Blueprint $table) {
15-
$table->bigIncrements('id');
16-
$table->unsignedBigInteger('user_id')->nullable()->index();
15+
$table->id();
16+
$table->foreignId('user_id')->nullable()->index();
1717
$table->string('name');
1818
$table->string('secret', 100)->nullable();
1919
$table->string('provider')->nullable();
@@ -32,4 +32,14 @@ public function down(): void
3232
{
3333
Schema::dropIfExists('oauth_clients');
3434
}
35+
36+
/**
37+
* Get the migration connection name.
38+
*
39+
* @return string|null
40+
*/
41+
public function getConnection()
42+
{
43+
return $this->connection ?? config('passport.connection');
44+
}
3545
};

src/Console/InstallCommand.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ protected function configureUuids()
6666
Passport::setClientUuids(true);
6767

6868
$this->replaceInFile(config_path('passport.php'), '\'client_uuids\' => false', '\'client_uuids\' => true');
69-
$this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_auth_codes_table.php'), '$table->unsignedBigInteger(\'client_id\');', '$table->uuid(\'client_id\');');
70-
$this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_access_tokens_table.php'), '$table->unsignedBigInteger(\'client_id\');', '$table->uuid(\'client_id\');');
71-
$this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_clients_table.php'), '$table->bigIncrements(\'id\');', '$table->uuid(\'id\')->primary();');
69+
$this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_auth_codes_table.php'), '$table->foreignId(\'client_id\');', '$table->foreignUuid(\'client_id\');');
70+
$this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_access_tokens_table.php'), '$table->foreignId(\'client_id\');', '$table->foreignUuid(\'client_id\');');
71+
$this->replaceInFile(database_path('migrations/****_**_**_******_create_oauth_clients_table.php'), '$table->id();', '$table->uuid(\'id\')->primary();');
7272
}
7373

7474
/**

0 commit comments

Comments
 (0)