@@ -20,106 +20,96 @@ public function up(): void
2020 throw_if (empty ($ tableNames ), new Exception ('Error: config/permission.php not loaded. Run [php artisan config:clear] and try again. ' ));
2121 throw_if ($ teams && empty ($ columnNames ['team_foreign_key ' ] ?? null ), new Exception ('Error: team_foreign_key on config/permission.php not loaded. Run [php artisan config:clear] and try again. ' ));
2222
23- if (! Schema::hasTable ($ tableNames ['permissions ' ])) {
24- Schema::create ($ tableNames ['permissions ' ], static function (Blueprint $ table ) {
25- // $table->engine('InnoDB');
26- $ table ->bigIncrements ('id ' ); // permission id
27- $ table ->string ('name ' ); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format)
28- $ table ->string ('guard_name ' ); // For MyISAM use string('guard_name', 25);
29- $ table ->timestamps ();
30-
23+ Schema::create ($ tableNames ['permissions ' ], static function (Blueprint $ table ) {
24+ // $table->engine('InnoDB');
25+ $ table ->bigIncrements ('id ' ); // permission id
26+ $ table ->string ('name ' ); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format)
27+ $ table ->string ('guard_name ' ); // For MyISAM use string('guard_name', 25);
28+ $ table ->timestamps ();
29+
30+ $ table ->unique (['name ' , 'guard_name ' ]);
31+ });
32+
33+ Schema::create ($ tableNames ['roles ' ], static function (Blueprint $ table ) use ($ teams , $ columnNames ) {
34+ // $table->engine('InnoDB');
35+ $ table ->bigIncrements ('id ' ); // role id
36+ if ($ teams || config ('permission.testing ' )) { // permission.testing is a fix for sqlite testing
37+ $ table ->unsignedBigInteger ($ columnNames ['team_foreign_key ' ])->nullable ();
38+ $ table ->index ($ columnNames ['team_foreign_key ' ], 'roles_team_foreign_key_index ' );
39+ }
40+ $ table ->string ('name ' ); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format)
41+ $ table ->string ('guard_name ' ); // For MyISAM use string('guard_name', 25);
42+ $ table ->timestamps ();
43+ if ($ teams || config ('permission.testing ' )) {
44+ $ table ->unique ([$ columnNames ['team_foreign_key ' ], 'name ' , 'guard_name ' ]);
45+ } else {
3146 $ table ->unique (['name ' , 'guard_name ' ]);
32- });
33- }
34-
35- if (! Schema::hasTable ($ tableNames ['roles ' ])) {
36- Schema::create ($ tableNames ['roles ' ], static function (Blueprint $ table ) use ($ teams , $ columnNames ) {
37- // $table->engine('InnoDB');
38- $ table ->bigIncrements ('id ' ); // role id
39- if ($ teams || config ('permission.testing ' )) { // permission.testing is a fix for sqlite testing
40- $ table ->unsignedBigInteger ($ columnNames ['team_foreign_key ' ])->nullable ();
41- $ table ->index ($ columnNames ['team_foreign_key ' ], 'roles_team_foreign_key_index ' );
42- }
43- $ table ->string ('name ' ); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format)
44- $ table ->string ('guard_name ' ); // For MyISAM use string('guard_name', 25);
45- $ table ->timestamps ();
46- if ($ teams || config ('permission.testing ' )) {
47- $ table ->unique ([$ columnNames ['team_foreign_key ' ], 'name ' , 'guard_name ' ]);
48- } else {
49- $ table ->unique (['name ' , 'guard_name ' ]);
50- }
51- });
52- }
53-
54- if (! Schema::hasTable ($ tableNames ['model_has_permissions ' ])) {
55- Schema::create ($ tableNames ['model_has_permissions ' ], static function (Blueprint $ table ) use ($ tableNames , $ columnNames , $ pivotPermission , $ teams ) {
56- $ table ->unsignedBigInteger ($ pivotPermission );
57-
58- $ table ->string ('model_type ' );
59- $ table ->unsignedBigInteger ($ columnNames ['model_morph_key ' ]);
60- $ table ->index ([$ columnNames ['model_morph_key ' ], 'model_type ' ], 'model_has_permissions_model_id_model_type_index ' );
61-
62- $ table ->foreign ($ pivotPermission )
63- ->references ('id ' ) // permission id
64- ->on ($ tableNames ['permissions ' ])
65- ->onDelete ('cascade ' );
66- if ($ teams ) {
67- $ table ->unsignedBigInteger ($ columnNames ['team_foreign_key ' ]);
68- $ table ->index ($ columnNames ['team_foreign_key ' ], 'model_has_permissions_team_foreign_key_index ' );
69-
70- $ table ->primary ([$ columnNames ['team_foreign_key ' ], $ pivotPermission , $ columnNames ['model_morph_key ' ], 'model_type ' ],
71- 'model_has_permissions_permission_model_type_primary ' );
72- } else {
73- $ table ->primary ([$ pivotPermission , $ columnNames ['model_morph_key ' ], 'model_type ' ],
74- 'model_has_permissions_permission_model_type_primary ' );
75- }
76-
77- });
78- }
79-
80- if (! Schema::hasTable ($ tableNames ['model_has_roles ' ])) {
81- Schema::create ($ tableNames ['model_has_roles ' ], static function (Blueprint $ table ) use ($ tableNames , $ columnNames , $ pivotRole , $ teams ) {
82- $ table ->unsignedBigInteger ($ pivotRole );
83-
84- $ table ->string ('model_type ' );
85- $ table ->unsignedBigInteger ($ columnNames ['model_morph_key ' ]);
86- $ table ->index ([$ columnNames ['model_morph_key ' ], 'model_type ' ], 'model_has_roles_model_id_model_type_index ' );
87-
88- $ table ->foreign ($ pivotRole )
89- ->references ('id ' ) // role id
90- ->on ($ tableNames ['roles ' ])
91- ->onDelete ('cascade ' );
92- if ($ teams ) {
93- $ table ->unsignedBigInteger ($ columnNames ['team_foreign_key ' ]);
94- $ table ->index ($ columnNames ['team_foreign_key ' ], 'model_has_roles_team_foreign_key_index ' );
95-
96- $ table ->primary ([$ columnNames ['team_foreign_key ' ], $ pivotRole , $ columnNames ['model_morph_key ' ], 'model_type ' ],
97- 'model_has_roles_role_model_type_primary ' );
98- } else {
99- $ table ->primary ([$ pivotRole , $ columnNames ['model_morph_key ' ], 'model_type ' ],
100- 'model_has_roles_role_model_type_primary ' );
101- }
102- });
103- }
104-
105- if (! Schema::hasTable ($ tableNames ['role_has_permissions ' ])) {
106- Schema::create ($ tableNames ['role_has_permissions ' ], static function (Blueprint $ table ) use ($ tableNames , $ pivotRole , $ pivotPermission ) {
107- $ table ->unsignedBigInteger ($ pivotPermission );
108- $ table ->unsignedBigInteger ($ pivotRole );
109-
110- $ table ->foreign ($ pivotPermission )
111- ->references ('id ' ) // permission id
112- ->on ($ tableNames ['permissions ' ])
113- ->onDelete ('cascade ' );
114-
115- $ table ->foreign ($ pivotRole )
116- ->references ('id ' ) // role id
117- ->on ($ tableNames ['roles ' ])
118- ->onDelete ('cascade ' );
119-
120- $ table ->primary ([$ pivotPermission , $ pivotRole ], 'role_has_permissions_permission_id_role_id_primary ' );
121- });
122- }
47+ }
48+ });
49+
50+ Schema::create ($ tableNames ['model_has_permissions ' ], static function (Blueprint $ table ) use ($ tableNames , $ columnNames , $ pivotPermission , $ teams ) {
51+ $ table ->unsignedBigInteger ($ pivotPermission );
52+
53+ $ table ->string ('model_type ' );
54+ $ table ->unsignedBigInteger ($ columnNames ['model_morph_key ' ]);
55+ $ table ->index ([$ columnNames ['model_morph_key ' ], 'model_type ' ], 'model_has_permissions_model_id_model_type_index ' );
56+
57+ $ table ->foreign ($ pivotPermission )
58+ ->references ('id ' ) // permission id
59+ ->on ($ tableNames ['permissions ' ])
60+ ->onDelete ('cascade ' );
61+ if ($ teams ) {
62+ $ table ->unsignedBigInteger ($ columnNames ['team_foreign_key ' ]);
63+ $ table ->index ($ columnNames ['team_foreign_key ' ], 'model_has_permissions_team_foreign_key_index ' );
64+
65+ $ table ->primary ([$ columnNames ['team_foreign_key ' ], $ pivotPermission , $ columnNames ['model_morph_key ' ], 'model_type ' ],
66+ 'model_has_permissions_permission_model_type_primary ' );
67+ } else {
68+ $ table ->primary ([$ pivotPermission , $ columnNames ['model_morph_key ' ], 'model_type ' ],
69+ 'model_has_permissions_permission_model_type_primary ' );
70+ }
71+
72+ });
73+
74+ Schema::create ($ tableNames ['model_has_roles ' ], static function (Blueprint $ table ) use ($ tableNames , $ columnNames , $ pivotRole , $ teams ) {
75+ $ table ->unsignedBigInteger ($ pivotRole );
76+
77+ $ table ->string ('model_type ' );
78+ $ table ->unsignedBigInteger ($ columnNames ['model_morph_key ' ]);
79+ $ table ->index ([$ columnNames ['model_morph_key ' ], 'model_type ' ], 'model_has_roles_model_id_model_type_index ' );
80+
81+ $ table ->foreign ($ pivotRole )
82+ ->references ('id ' ) // role id
83+ ->on ($ tableNames ['roles ' ])
84+ ->onDelete ('cascade ' );
85+ if ($ teams ) {
86+ $ table ->unsignedBigInteger ($ columnNames ['team_foreign_key ' ]);
87+ $ table ->index ($ columnNames ['team_foreign_key ' ], 'model_has_roles_team_foreign_key_index ' );
88+
89+ $ table ->primary ([$ columnNames ['team_foreign_key ' ], $ pivotRole , $ columnNames ['model_morph_key ' ], 'model_type ' ],
90+ 'model_has_roles_role_model_type_primary ' );
91+ } else {
92+ $ table ->primary ([$ pivotRole , $ columnNames ['model_morph_key ' ], 'model_type ' ],
93+ 'model_has_roles_role_model_type_primary ' );
94+ }
95+ });
96+
97+ Schema::create ($ tableNames ['role_has_permissions ' ], static function (Blueprint $ table ) use ($ tableNames , $ pivotRole , $ pivotPermission ) {
98+ $ table ->unsignedBigInteger ($ pivotPermission );
99+ $ table ->unsignedBigInteger ($ pivotRole );
100+
101+ $ table ->foreign ($ pivotPermission )
102+ ->references ('id ' ) // permission id
103+ ->on ($ tableNames ['permissions ' ])
104+ ->onDelete ('cascade ' );
105+
106+ $ table ->foreign ($ pivotRole )
107+ ->references ('id ' ) // role id
108+ ->on ($ tableNames ['roles ' ])
109+ ->onDelete ('cascade ' );
110+
111+ $ table ->primary ([$ pivotPermission , $ pivotRole ], 'role_has_permissions_permission_id_role_id_primary ' );
112+ });
123113
124114 app ('cache ' )
125115 ->store (config ('permission.cache.store ' ) != 'default ' ? config ('permission.cache.store ' ) : null )
0 commit comments