Welcome Guest, Not a member yet? Register   Sign In
SHIELD - Table name
#1

Perhaps Shield table name has been used for other project.

Suggestion: Make the table name customizable like CodeIgniter Settings or Ion Auth
Reply
#2

Hi, can you explain why two Auth packages should be used simultaneously on the same site?
Reply
#3

Let's say some workplaces have policies and procedures for table names to follow a standard like ISO
Reply
#4

(08-02-2022, 06:10 PM)datamweb Wrote: Hi, can you explain why two Auth packages should be used simultaneously on the same site?

My suggestion

Create constant for auth tables in Config/Auth.php. For example tbl_auth

PHP Code:
...
use 
CodeIgniter\Shield\Authentication\Passwords\ValidatorInterface;
use 
CodeIgniter\Shield\Models\UserModel;

define('tbl_auth', [
    'users' => 'users',
    'identities' => 'auth_identities',
    'logins' => 'auth_logins',
    'token_logins' => 'auth_token_logins',
    'remember_tokens' => 'auth_remember_tokens',
    'groups_users' => 'auth_groups_users',
    'permissions_users' => 'auth_permissions_users',
]);

class 
Auth extends ShieldAuth
{
... 

And use it within the file project.

Ie migration
PHP Code:
..
$this->forge->createTable(tbl_auth['users']);
..
$this->forge->createTable(tbl_auth['identities']);
.. 

Models
PHP Code:
..
protected 
$table tbl_auth['users'];
..

$data $this->select(tbl_auth['users'] . '.*')
.. 
Reply
#5

(This post was last modified: 01-06-2023, 07:42 AM by superior.)

I agree with @nfaiz, a better approach would be a configurable option before running setup.
Not just for teamwork but you also might be using the same name(s) that can cause conflicts.

I think writing this in the Auth config would be a good place, as it contains the view override as well.

PHP Code:
/**
 * --------------------------------------------------------------------
 * Shield Tables
 * --------------------------------------------------------------------
 *
 */
public array $table = [
    'groups_users'      => 'auth_groups_users',
    'identities'        => 'auth_identities',
    'logins'            => 'auth_logins',
    'permissions_users' => 'auth_permissions_users',
    'remember_tokens'   => 'auth_remember_tokens',
    'token_logins'      => 'auth_token_logins',
];

// Example usage:
config('Auth')->table['groups_users']; 
Reply
#6

Now you will have problems with the Database Migrations.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

(This post was last modified: 01-07-2023, 01:32 AM by kenjis.)

Yes, if you add the table property, the database migration also needs to use the values.

And of course, if you change the property after initial setup, you also need to change the table names by yourself.
Reply
#8

(This post was last modified: 01-09-2023, 11:17 PM by nfaiz.)

(01-07-2023, 01:32 AM)kenjis Wrote: Yes, if you add the table property, the database migration also needs to use the values.

And of course, if you change the property after initial setup, you also need to change the table names by yourself.

How about change the workflow.

To run migrations after constants/properties in Auth.php config has been set (if needed).
Reply
#9

See https://github.com/codeigniter4/shield/pull/633
Reply
#10

(02-12-2023, 11:52 PM)kenjis Wrote: See https://github.com/codeigniter4/shield/pull/633

Thank you @kenjis and @datamweb. Really appreciate it.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB