Skip to content

Commit

Permalink
Merge pull request #254 from pennyappeal-charity/master
Browse files Browse the repository at this point in the history
Bugfix: cannot install package if the users table has a different name
  • Loading branch information
kodeine authored May 14, 2020
2 parents 06aa6d2 + ae3b727 commit e428103
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
11 changes: 11 additions & 0 deletions src/Kodeine/Acl/Helper/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Kodeine\Acl\Helper;

class Config
{
public static function usersTableName()
{
return config('acl.users_table') === '' ? 'users' : config('acl.users_table');
}
}
12 changes: 9 additions & 3 deletions src/migrations/2015_02_07_172633_create_role_user_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Kodeine\Acl\Helper\Config;

class CreateRoleUserTable extends Migration
{
Expand All @@ -13,7 +14,6 @@ class CreateRoleUserTable extends Migration
public function __construct()
{
$this->prefix = config('acl.db_prefix');
$this->users_table = config('acl.users_table') === '' ? 'users' : config('acl.users_table');
}

/**
Expand All @@ -27,7 +27,13 @@ public function up()
$table->increments('id');

$table->integer('role_id')->unsigned()->index()->foreign()->references("id")->on("roles")->onDelete("cascade");
$table->bigInteger('user_id')->unsigned()->index()->foreign()->references("id")->on("users")->onDelete("cascade");
$table->bigInteger('user_id')
->unsigned()
->index()
->foreign()
->references("id")
->on(Config::usersTableName())
->onDelete("cascade");

$table->timestamps();

Expand All @@ -38,7 +44,7 @@ public function up()

$table->foreign('user_id')
->references('id')
->on($this->prefix . 'users')
->on($this->prefix . Config::usersTableName())
->onDelete('cascade');
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Kodeine\Acl\Helper\Config;

class CreatePermissionUserTable extends Migration
{
Expand All @@ -25,7 +26,12 @@ public function up()
Schema::create($this->prefix . 'permission_user', function (Blueprint $table) {
$table->increments('id');
$table->integer('permission_id')->unsigned()->index()->references('id')->on('permissions')->onDelete('cascade');
$table->bigInteger('user_id')->unsigned()->index()->references('id')->on('users')->onDelete('cascade');
$table->bigInteger('user_id')
->unsigned()
->index()
->references('id')
->on(Config::usersTableName())
->onDelete('cascade');
$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Kodeine\Acl\Helper\Config;

class CreateUsersTableIfDoesntExist extends Migration
{

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (!Schema::hasTable('users')) {
Schema::create('users', function (Blueprint $table) {
if (!Schema::hasTable(Config::usersTableName())) {
Schema::create(Config::usersTableName(), function (Blueprint $table) {
$table->increments('id');
$table->string('username');
$table->string('first_name', 30)->nullable();
Expand All @@ -34,6 +34,8 @@ public function up()
*/
public function down()
{
Schema::drop('users');
// @todo Are you sure? What if there was already a users table and the up() method above did nothing?
// Would it not be safer to leave a dangling unused table than to drop a potentially vital table?
// Schema::drop('users');
}
}

0 comments on commit e428103

Please sign in to comment.