CodeIgniter Forums
SHIELD - Table name - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29)
+--- Thread: SHIELD - Table name (/showthread.php?tid=82321)



SHIELD - Table name - nfaiz - 06-30-2022

Perhaps Shield table name has been used for other project.

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


RE: SHIELD - Table name - datamweb - 08-02-2022

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


RE: SHIELD - Table name - nfaiz - 08-07-2022

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


RE: SHIELD - Table name - nfaiz - 01-06-2023

(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'] . '.*')
.. 



RE: SHIELD - Table name - superior - 01-06-2023

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']; 



RE: SHIELD - Table name - InsiteFX - 01-07-2023

Now you will have problems with the Database Migrations.


RE: SHIELD - Table name - kenjis - 01-07-2023

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.


RE: SHIELD - Table name - nfaiz - 01-09-2023

(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).


RE: SHIELD - Table name - kenjis - 02-12-2023

See https://github.com/codeigniter4/shield/pull/633


RE: SHIELD - Table name - nfaiz - 02-13-2023

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

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