mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-04-09 17:31:58 +02:00
Add cascade delete on AuthLog table
This commit is contained in:
parent
4987e060c4
commit
99bf9d7d80
@ -41,11 +41,20 @@ public function up(): void
|
||||
$table->boolean('cleared_by_user')->default(false);
|
||||
$table->string('guard', 40)->nullable();
|
||||
$table->string('login_method', 40)->nullable();
|
||||
|
||||
$table->foreign('authenticatable_id')->references('id')->on('users')->cascadeOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::whenTableHasColumn('auth_logs', 'authenticatable_id', function (Blueprint $table) {
|
||||
// cannot drop foreign keys in SQLite:
|
||||
if (DB::getDriverName() !== 'sqlite') {
|
||||
$table->dropForeign(['authenticatable_id']);
|
||||
}
|
||||
});
|
||||
|
||||
Schema::dropIfExists('auth_logs');
|
||||
}
|
||||
};
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Feature\Models;
|
||||
|
||||
use App\Models\AuthLog;
|
||||
use App\Models\Group;
|
||||
use App\Models\TwoFAccount;
|
||||
use App\Models\User;
|
||||
@ -113,6 +114,7 @@ public function test_delete_removes_user_data()
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
TwoFAccount::factory()->for($user)->create();
|
||||
AuthLog::factory()->for($user, 'authenticatable')->create();
|
||||
Group::factory()->for($user)->create();
|
||||
|
||||
DB::table('webauthn_credentials')->insert([
|
||||
@ -154,6 +156,9 @@ public function test_delete_removes_user_data()
|
||||
$this->assertDatabaseMissing(config('auth.passwords.users.table'), [
|
||||
'email' => $user->email,
|
||||
]);
|
||||
$this->assertDatabaseMissing('auth_logs', [
|
||||
'authenticatable_id' => $user->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user