4
4
use Illuminate \Database \Schema \Blueprint ;
5
5
use Illuminate \Support \Facades \Schema ;
6
6
7
- class CreatePermissionTables extends Migration
7
+ return new class extends Migration
8
8
{
9
9
public function up ()
10
10
{
11
- Schema::create ('roles ' , function (Blueprint $ table ) {
12
- $ table ->id ();
13
- $ table ->string ('name ' )->unique ()->index ();
14
- $ table ->timestamps ();
15
- });
11
+ if (!Schema::hasTable ('roles ' )) {
12
+ Schema::create ('roles ' , function (Blueprint $ table ) {
13
+ $ table ->id ();
14
+ $ table ->string ('name ' )->unique ()->index ();
15
+ $ table ->timestamps ();
16
+ });
17
+ }
16
18
17
- Schema::create ('permissions ' , function (Blueprint $ table ) {
18
- $ table ->id ();
19
- $ table ->string ('name ' )->unique ()->index ();
20
- $ table ->timestamps ();
21
- });
19
+ if (!Schema::hasTable ('permissions ' )) {
20
+ Schema::create ('permissions ' , function (Blueprint $ table ) {
21
+ $ table ->id ();
22
+ $ table ->string ('name ' )->unique ()->index ();
23
+ $ table ->timestamps ();
24
+ });
25
+ }
22
26
23
- Schema::create ('role_permission ' , function (Blueprint $ table ) {
24
- $ table ->id ();
25
- $ table ->foreignId ('role_id ' )->constrained ()->onDelete ('cascade ' );
26
- $ table ->foreignId ('permission_id ' )->constrained ()->onDelete ('cascade ' );
27
- });
27
+ if (!Schema::hasTable ('role_permission ' )) {
28
+ Schema::create ('role_permission ' , function (Blueprint $ table ) {
29
+ $ table ->id ();
30
+ $ table ->foreignId ('role_id ' )->constrained ()->onDelete ('cascade ' );
31
+ $ table ->foreignId ('permission_id ' )->constrained ()->onDelete ('cascade ' );
32
+ });
33
+ }
28
34
}
29
35
30
36
public function down ()
@@ -33,4 +39,4 @@ public function down()
33
39
Schema::dropIfExists ('permissions ' );
34
40
Schema::dropIfExists ('roles ' );
35
41
}
36
- }
42
+ };
0 commit comments