mirror of
https://github.com/archtechx/tenancy.git
synced 2026-03-23 19:24:02 +00:00
Tenant DB manager database() -> connection()
This commit is contained in:
parent
f3e01c1581
commit
0fc105487b
13 changed files with 60 additions and 60 deletions
|
|
@ -21,26 +21,26 @@ class PermissionControlledPostgreSQLDatabaseManager extends PostgreSQLDatabaseMa
|
|||
$schema = $databaseConfig->connection()['search_path'];
|
||||
|
||||
// Host config
|
||||
$connectionName = $this->database()->getConfig('name');
|
||||
$centralDatabase = $this->database()->getConfig('database');
|
||||
$connectionName = $this->connection()->getConfig('name');
|
||||
$centralDatabase = $this->connection()->getConfig('database');
|
||||
|
||||
$this->database()->statement("GRANT CONNECT ON DATABASE \"{$database}\" TO \"{$username}\"");
|
||||
$this->connection()->statement("GRANT CONNECT ON DATABASE \"{$database}\" TO \"{$username}\"");
|
||||
|
||||
// Connect to tenant database
|
||||
config(["database.connections.{$connectionName}.database" => $database]);
|
||||
|
||||
$this->database()->reconnect();
|
||||
$this->connection()->reconnect();
|
||||
|
||||
// Grant permissions to create and use tables in the configured schema ("public" by default) to the user
|
||||
$this->database()->statement("GRANT USAGE, CREATE ON SCHEMA {$schema} TO \"{$username}\"");
|
||||
$this->connection()->statement("GRANT USAGE, CREATE ON SCHEMA {$schema} TO \"{$username}\"");
|
||||
|
||||
// Grant permissions to use sequences in the current schema to the user
|
||||
$this->database()->statement("GRANT USAGE ON ALL SEQUENCES IN SCHEMA {$schema} TO \"{$username}\"");
|
||||
$this->connection()->statement("GRANT USAGE ON ALL SEQUENCES IN SCHEMA {$schema} TO \"{$username}\"");
|
||||
|
||||
// Reconnect to central database
|
||||
config(["database.connections.{$connectionName}.database" => $centralDatabase]);
|
||||
|
||||
$this->database()->reconnect();
|
||||
$this->connection()->reconnect();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue