diff --git a/src/database/migrations/create_permission_tables.php b/src/database/migrations/create_permission_tables.php index 03bcf54..0e1d22e 100644 --- a/src/database/migrations/create_permission_tables.php +++ b/src/database/migrations/create_permission_tables.php @@ -4,27 +4,33 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class CreatePermissionTables extends Migration +return new class extends Migration { public function up() { - Schema::create('roles', function (Blueprint $table) { - $table->id(); - $table->string('name')->unique()->index(); - $table->timestamps(); - }); + if (!Schema::hasTable('roles')) { + Schema::create('roles', function (Blueprint $table) { + $table->id(); + $table->string('name')->unique()->index(); + $table->timestamps(); + }); + } - Schema::create('permissions', function (Blueprint $table) { - $table->id(); - $table->string('name')->unique()->index(); - $table->timestamps(); - }); + if (!Schema::hasTable('permissions')) { + Schema::create('permissions', function (Blueprint $table) { + $table->id(); + $table->string('name')->unique()->index(); + $table->timestamps(); + }); + } - Schema::create('role_permission', function (Blueprint $table) { - $table->id(); - $table->foreignId('role_id')->constrained()->onDelete('cascade'); - $table->foreignId('permission_id')->constrained()->onDelete('cascade'); - }); + if (!Schema::hasTable('role_permission')) { + Schema::create('role_permission', function (Blueprint $table) { + $table->id(); + $table->foreignId('role_id')->constrained()->onDelete('cascade'); + $table->foreignId('permission_id')->constrained()->onDelete('cascade'); + }); + } } public function down() @@ -33,4 +39,4 @@ public function down() Schema::dropIfExists('permissions'); Schema::dropIfExists('roles'); } -} +};