54 lines
1.8 KiB
PHP
54 lines
1.8 KiB
PHP
<?php
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
return new class extends Migration
|
|
{
|
|
public function up(): void
|
|
{
|
|
if (!Schema::hasColumn('users', 'permissions')) {
|
|
Schema::table('users', function (Blueprint $table) {
|
|
$table->json('permissions')->nullable()->after('is_admin');
|
|
});
|
|
}
|
|
|
|
if (!Schema::hasTable('activity_logs')) {
|
|
Schema::create('activity_logs', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->foreignId('user_id')->constrained()->onDelete('cascade');
|
|
$table->string('action');
|
|
$table->string('module');
|
|
$table->string('description')->nullable();
|
|
$table->json('details')->nullable();
|
|
$table->string('ip_address', 45)->nullable();
|
|
$table->timestamp('created_at')->useCurrent();
|
|
|
|
$table->index(['user_id', 'module']);
|
|
$table->index(['created_at']);
|
|
$table->index(['action']);
|
|
});
|
|
}
|
|
|
|
if (!Schema::hasTable('role_presets')) {
|
|
Schema::create('role_presets', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->string('name', 50)->unique();
|
|
$table->string('description')->nullable();
|
|
$table->json('permissions');
|
|
$table->timestamps();
|
|
});
|
|
}
|
|
}
|
|
|
|
public function down(): void
|
|
{
|
|
Schema::dropIfExists('activity_logs');
|
|
Schema::dropIfExists('role_presets');
|
|
|
|
Schema::table('users', function (Blueprint $table) {
|
|
$table->dropColumn('permissions');
|
|
});
|
|
}
|
|
}; |