php-casbin / database-adapter

Database adapter for PHP-Casbin, Casbin is a powerful and efficient open-source access control library.
Apache License 2.0
28 stars 5 forks source link

Bug custom rule table name #23

Closed rauwebieten closed 2 years ago

rauwebieten commented 2 years ago

I see in code that the initTable method is invoked in the constructor.

This means the db table is created (with the default name) before the casbinRuleTableName parameter can be set.

This also means the default table is -always- created, when you choose to use a custom table name.

I think it's better to remove the initTable invokation from the constructor, and let the developer use this method manually to create the tables.

leeqvip commented 2 years ago

@rauwebieten Which adapter are you using?

rauwebieten commented 2 years ago

I'm using the SQL adapter. https://github.com/php-casbin/database-adapter/ Guess I should submit this issue there?

Problem is (I think) following code in constructor of adapter:

public function __construct(array $config)
{
    $this->config = $config;
    $this->filtered = false;
    $this->connection = (new Manager($config))->getConnection();
    $this->initTable();
}

So initTable is called before the $casbinRuleTableName property can be modified.

hsluoyz commented 2 years ago

@linvery

leeqvip commented 2 years ago

@rauwebieten See https://github.com/php-casbin/database-adapter/pull/22/files