new funcionality
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('login_events', function (Blueprint $table) {
|
||||
// Default 'success' backfilla las filas existentes: hasta ahora
|
||||
// login_events solo registraba logins exitosos.
|
||||
$table->string('outcome')->default('success')->after('type');
|
||||
$table->index(['type', 'outcome', 'created_at']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('login_events', function (Blueprint $table) {
|
||||
$table->dropIndex(['type', 'outcome', 'created_at']);
|
||||
$table->dropColumn('outcome');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('oauth_authorization_events', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
|
||||
$table->foreignUuid('client_id')->nullable()->constrained('oauth_clients')->nullOnDelete();
|
||||
$table->string('outcome'); // 'attempted' | 'approved' | 'denied'
|
||||
$table->json('scopes')->nullable();
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
$table->string('user_agent')->nullable();
|
||||
$table->timestamp('created_at')->nullable();
|
||||
|
||||
$table->index(['created_at']);
|
||||
$table->index(['client_id', 'created_at']);
|
||||
$table->index(['outcome']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('oauth_authorization_events');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('audit_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('actor_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->string('action'); // 'user.created', 'client.revoked', etc.
|
||||
// subject_id es string (no FK/morphs): cubre tanto ids autoincrementales
|
||||
// (User) como uuid (Client) sin mezclar tipos en una sola columna.
|
||||
$table->string('subject_type'); // 'user' | 'client'
|
||||
$table->string('subject_id');
|
||||
// Snapshot de texto (email del usuario, nombre del client) al momento
|
||||
// del evento — sigue siendo legible aunque el sujeto se borre después.
|
||||
$table->string('subject_label')->nullable();
|
||||
// Se llama "metadata" y no "changes": ese nombre colisiona con la
|
||||
// propiedad protegida $changes que Eloquent usa internamente para
|
||||
// dirty-tracking (HasAttributes), y el choque solo se manifiesta
|
||||
// cuando se accede al atributo desde dentro de esta misma clase.
|
||||
$table->json('metadata')->nullable();
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
$table->string('user_agent')->nullable();
|
||||
$table->timestamp('created_at')->nullable();
|
||||
|
||||
$table->index(['created_at']);
|
||||
$table->index(['action', 'created_at']);
|
||||
$table->index(['subject_type', 'subject_id']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('audit_logs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* Backfilla el permiso "audit.view" para instalaciones ya sembradas
|
||||
* (RolesAndPermissionsSeeder solo corre en instalaciones nuevas o al
|
||||
* registrar el primer usuario) y se lo da al rol admin.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$permission = Permission::findOrCreate('audit.view');
|
||||
|
||||
$admin = Role::where('name', 'admin')->first();
|
||||
|
||||
if ($admin && ! $admin->hasPermissionTo($permission)) {
|
||||
$admin->givePermissionTo($permission);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Permission::where('name', 'audit.view')->delete();
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
// Guardados encriptados (cast 'encrypted'/'encrypted:array' en el
|
||||
// modelo) — por eso alcanza con "text" acá, no hace falta un tipo
|
||||
// especial. two_factor_confirmed_at null = activación pendiente
|
||||
// (secreto generado pero todavía no confirmado con un código) o
|
||||
// 2FA desactivado; no null = 2FA activo de verdad.
|
||||
$table->text('two_factor_secret')->nullable()->after('password');
|
||||
$table->text('two_factor_recovery_codes')->nullable()->after('two_factor_secret');
|
||||
$table->timestamp('two_factor_confirmed_at')->nullable()->after('two_factor_recovery_codes');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn(['two_factor_secret', 'two_factor_recovery_codes', 'two_factor_confirmed_at']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('webhook_endpoints', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignUuid('client_id')->constrained('oauth_clients')->cascadeOnDelete();
|
||||
$table->string('url');
|
||||
// Encriptado (cast 'encrypted' en el modelo) — a diferencia del
|
||||
// secret de un client OAuth, este SÍ hay que poder recuperarlo en
|
||||
// texto plano después para firmar cada entrega (HMAC), no solo
|
||||
// verificarlo una vez.
|
||||
$table->text('secret');
|
||||
$table->json('events'); // ej. ['token.revoked', 'user.deactivated']
|
||||
$table->boolean('active')->default(true);
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['client_id', 'active']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('webhook_endpoints');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('webhook_deliveries', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('webhook_endpoint_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('event');
|
||||
$table->json('payload');
|
||||
$table->unsignedSmallInteger('response_status')->nullable();
|
||||
$table->text('response_body')->nullable();
|
||||
$table->unsignedTinyInteger('attempts')->default(0);
|
||||
$table->timestamp('delivered_at')->nullable();
|
||||
$table->timestamp('created_at')->nullable();
|
||||
|
||||
$table->index(['webhook_endpoint_id', 'created_at']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('webhook_deliveries');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('oauth_clients', function (Blueprint $table) {
|
||||
// Copia del hash del secret anterior (no se re-hashea, ya viene
|
||||
// hasheado de la columna "secret") — sigue siendo válido hasta
|
||||
// previous_secret_expires_at, para no cortar integraciones que
|
||||
// todavía no se actualizaron al secret nuevo.
|
||||
$table->text('previous_secret')->nullable()->after('secret');
|
||||
$table->timestamp('previous_secret_expires_at')->nullable()->after('previous_secret');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('oauth_clients', function (Blueprint $table) {
|
||||
$table->dropColumn(['previous_secret', 'previous_secret_expires_at']);
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user