mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-04-22 00:19:03 +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->boolean('cleared_by_user')->default(false);
|
||||||
$table->string('guard', 40)->nullable();
|
$table->string('guard', 40)->nullable();
|
||||||
$table->string('login_method', 40)->nullable();
|
$table->string('login_method', 40)->nullable();
|
||||||
|
|
||||||
|
$table->foreign('authenticatable_id')->references('id')->on('users')->cascadeOnDelete();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function down(): void
|
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');
|
Schema::dropIfExists('auth_logs');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Tests\Feature\Models;
|
namespace Tests\Feature\Models;
|
||||||
|
|
||||||
|
use App\Models\AuthLog;
|
||||||
use App\Models\Group;
|
use App\Models\Group;
|
||||||
use App\Models\TwoFAccount;
|
use App\Models\TwoFAccount;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
@ -113,6 +114,7 @@ public function test_delete_removes_user_data()
|
|||||||
{
|
{
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
TwoFAccount::factory()->for($user)->create();
|
TwoFAccount::factory()->for($user)->create();
|
||||||
|
AuthLog::factory()->for($user, 'authenticatable')->create();
|
||||||
Group::factory()->for($user)->create();
|
Group::factory()->for($user)->create();
|
||||||
|
|
||||||
DB::table('webauthn_credentials')->insert([
|
DB::table('webauthn_credentials')->insert([
|
||||||
@ -154,6 +156,9 @@ public function test_delete_removes_user_data()
|
|||||||
$this->assertDatabaseMissing(config('auth.passwords.users.table'), [
|
$this->assertDatabaseMissing(config('auth.passwords.users.table'), [
|
||||||
'email' => $user->email,
|
'email' => $user->email,
|
||||||
]);
|
]);
|
||||||
|
$this->assertDatabaseMissing('auth_logs', [
|
||||||
|
'authenticatable_id' => $user->id,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user