Skip to content

Instantly share code, notes, and snippets.

@njxqlus
Last active June 27, 2017 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save njxqlus/1204f9079f2f96860b3ccecfc34ea928 to your computer and use it in GitHub Desktop.
Save njxqlus/1204f9079f2f96860b3ccecfc34ea928 to your computer and use it in GitHub Desktop.
Laravel Passport Oauth tables reservation (saver)

Laravel Passport OAuth tables reservation (saver)

These seeders is very usefull, when you want php artisan migrate:reset or php artisan migrate:refresh. After full migration reset you need to php artisan passport:install because newly created oauth tables is empty, but if you will use these gists, you will save some time and most importantly - save your current tokens.

Instruction

  1. Run php artisan db:seed with only $this->call(OauthTablesReservation::class);
  2. Delete this line from DatabaseSeeder. Do any operations you want, like php artisan migrate:refresh
  3. Run php artisan db:seed with only $this->call(OauthTablesSeeder::class);
<?php
use Illuminate\Database\Seeder;
class OauthTablesReservation extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$oauth_tables = [
'oauth_access_tokens',
'oauth_auth_codes',
'oauth_clients',
'oauth_personal_access_clients',
'oauth_refresh_tokens',
];
foreach ($oauth_tables as $table) {
DB::statement('DROP TABLE IF EXISTS reserved_' . $table);
DB::statement('CREATE TABLE reserved_' . $table . ' LIKE ' . $table);
DB::statement('INSERT reserved_' . $table . ' SELECT * FROM ' . $table);
}
}
}
<?php
use Illuminate\Database\Seeder;
class OauthTablesSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$oauth_tables = [
'oauth_access_tokens',
'oauth_auth_codes',
'oauth_clients',
'oauth_personal_access_clients',
'oauth_refresh_tokens',
];
foreach ($oauth_tables as $table) {
DB::statement('DROP TABLE IF EXISTS ' . $table);
DB::statement('CREATE TABLE ' . $table . ' LIKE reserved_' . $table);
DB::statement('INSERT ' . $table . ' SELECT * FROM reserved_' . $table);
DB::statement('DROP TABLE IF EXISTS reserved_' . $table);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment