fix: wrap seeders in db transactions (#11360)
This commit is contained in:
parent
a9ae9caedc
commit
911f6f5dfc
2 changed files with 44 additions and 39 deletions
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
use App\Models\OauthSetting;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class OauthSettingSeeder extends Seeder
|
||||
|
|
@ -43,6 +44,7 @@ public function run(): void
|
|||
return;
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($providers) {
|
||||
$allProviders = OauthSetting::all();
|
||||
$notFoundProviders = $providers->diff($allProviders->pluck('provider'));
|
||||
|
||||
|
|
@ -59,9 +61,10 @@ public function run(): void
|
|||
'provider' => $provider,
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
Log::error('OauthSettingSeeder failed: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
use App\Models\Team;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PersonalAccessTokenSeeder extends Seeder
|
||||
{
|
||||
|
|
@ -74,6 +74,7 @@ public function run(): void
|
|||
],
|
||||
];
|
||||
|
||||
DB::transaction(function () use ($user, $team, $testTokens) {
|
||||
// First, remove all existing development tokens for this user
|
||||
$deletedCount = PersonalAccessToken::where('tokenable_id', $user->id)
|
||||
->where('tokenable_type', get_class($user))
|
||||
|
|
@ -101,6 +102,7 @@ public function run(): void
|
|||
|
||||
$this->command->info("Created token '{$tokenData['name']}' with Bearer token: {$plainTextToken}");
|
||||
}
|
||||
});
|
||||
|
||||
$this->command->info('');
|
||||
$this->command->info('Test API tokens created successfully!');
|
||||
|
|
|
|||
Loading…
Reference in a new issue