File tree Expand file tree Collapse file tree 4 files changed +33
-8
lines changed Expand file tree Collapse file tree 4 files changed +33
-8
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Kodeine \Acl \Helper ;
4+
5+ class Config
6+ {
7+ public static function usersTableName ()
8+ {
9+ return config ('acl.users_table ' ) === '' ? 'users ' : config ('acl.users_table ' );
10+ }
11+ }
Original file line number Diff line number Diff line change 22
33use Illuminate \Database \Schema \Blueprint ;
44use Illuminate \Database \Migrations \Migration ;
5+ use Kodeine \Acl \Helper \Config ;
56
67class CreateRoleUserTable extends Migration
78{
@@ -13,7 +14,6 @@ class CreateRoleUserTable extends Migration
1314 public function __construct ()
1415 {
1516 $ this ->prefix = config ('acl.db_prefix ' );
16- $ this ->users_table = config ('acl.users_table ' ) === '' ? 'users ' : config ('acl.users_table ' );
1717 }
1818
1919 /**
@@ -27,7 +27,13 @@ public function up()
2727 $ table ->increments ('id ' );
2828
2929 $ table ->integer ('role_id ' )->unsigned ()->index ()->foreign ()->references ("id " )->on ("roles " )->onDelete ("cascade " );
30- $ table ->bigInteger ('user_id ' )->unsigned ()->index ()->foreign ()->references ("id " )->on ("users " )->onDelete ("cascade " );
30+ $ table ->bigInteger ('user_id ' )
31+ ->unsigned ()
32+ ->index ()
33+ ->foreign ()
34+ ->references ("id " )
35+ ->on (Config::usersTableName ())
36+ ->onDelete ("cascade " );
3137
3238 $ table ->timestamps ();
3339
@@ -38,7 +44,7 @@ public function up()
3844
3945 $ table ->foreign ('user_id ' )
4046 ->references ('id ' )
41- ->on ($ this ->prefix . ' users ' )
47+ ->on ($ this ->prefix . Config:: usersTableName () )
4248 ->onDelete ('cascade ' );
4349 });
4450 }
Original file line number Diff line number Diff line change 22
33use Illuminate \Database \Schema \Blueprint ;
44use Illuminate \Database \Migrations \Migration ;
5+ use Kodeine \Acl \Helper \Config ;
56
67class CreatePermissionUserTable extends Migration
78{
@@ -25,7 +26,12 @@ public function up()
2526 Schema::create ($ this ->prefix . 'permission_user ' , function (Blueprint $ table ) {
2627 $ table ->increments ('id ' );
2728 $ table ->integer ('permission_id ' )->unsigned ()->index ()->references ('id ' )->on ('permissions ' )->onDelete ('cascade ' );
28- $ table ->bigInteger ('user_id ' )->unsigned ()->index ()->references ('id ' )->on ('users ' )->onDelete ('cascade ' );
29+ $ table ->bigInteger ('user_id ' )
30+ ->unsigned ()
31+ ->index ()
32+ ->references ('id ' )
33+ ->on (Config::usersTableName ())
34+ ->onDelete ('cascade ' );
2935 $ table ->timestamps ();
3036 });
3137 }
Original file line number Diff line number Diff line change 22
33use Illuminate \Database \Schema \Blueprint ;
44use Illuminate \Database \Migrations \Migration ;
5+ use Kodeine \Acl \Helper \Config ;
56
67class CreateUsersTableIfDoesntExist extends Migration
78{
8-
99 /**
1010 * Run the migrations.
1111 *
1212 * @return void
1313 */
1414 public function up ()
1515 {
16- if (!Schema::hasTable (' users ' )) {
17- Schema::create (' users ' , function (Blueprint $ table ) {
16+ if (!Schema::hasTable (Config:: usersTableName () )) {
17+ Schema::create (Config:: usersTableName () , function (Blueprint $ table ) {
1818 $ table ->increments ('id ' );
1919 $ table ->string ('username ' );
2020 $ table ->string ('first_name ' , 30 )->nullable ();
@@ -34,6 +34,8 @@ public function up()
3434 */
3535 public function down ()
3636 {
37- Schema::drop ('users ' );
37+ // @todo Are you sure? What if there was already a users table and the up() method above did nothing?
38+ // Would it not be safer to leave a dangling unused table than to drop a potentially vital table?
39+ // Schema::drop('users');
3840 }
3941}
You can’t perform that action at this time.
0 commit comments