Add cascade delete on AuthLog table

This commit is contained in:
Bubka
2024-04-25 13:21:24 +02:00
parent 4987e060c4
commit 99bf9d7d80
2 changed files with 14 additions and 0 deletions

View File

@ -41,11 +41,20 @@ return new class extends Migration
$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');
}
};