<?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 { Schema::create('users',function(Blueprint $t){$t->id();$t->string('name');$t->string('email')->unique();$t->timestamp('email_verified_at')->nullable();$t->string('password');$t->string('status')->default('active')->index();$t->timestamp('last_login_at')->nullable();$t->rememberToken();$t->timestamps();}); Schema::create('password_reset_tokens',function(Blueprint $t){$t->string('email')->primary();$t->string('token');$t->timestamp('created_at')->nullable();}); Schema::create('sessions',function(Blueprint $t){$t->string('id')->primary();$t->foreignId('user_id')->nullable()->index();$t->string('ip_address',45)->nullable();$t->text('user_agent')->nullable();$t->longText('payload');$t->integer('last_activity')->index();}); Schema::create('roles',function(Blueprint $t){$t->id();$t->string('name');$t->string('slug')->unique();$t->timestamps();}); Schema::create('permissions',function(Blueprint $t){$t->id();$t->string('name');$t->string('slug')->unique();$t->timestamps();}); Schema::create('role_user',function(Blueprint $t){$t->foreignId('role_id')->constrained()->cascadeOnDelete();$t->foreignId('user_id')->constrained()->cascadeOnDelete();$t->primary(['role_id','user_id']);}); Schema::create('permission_role',function(Blueprint $t){$t->foreignId('permission_id')->constrained()->cascadeOnDelete();$t->foreignId('role_id')->constrained()->cascadeOnDelete();$t->primary(['permission_id','role_id']);}); } public function down():void { Schema::dropIfExists('permission_role');Schema::dropIfExists('role_user');Schema::dropIfExists('permissions');Schema::dropIfExists('roles');Schema::dropIfExists('sessions');Schema::dropIfExists('password_reset_tokens');Schema::dropIfExists('users'); } };
