mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-04 20:54:03 +00:00
Rename bootstrapper, improve docblock
This commit is contained in:
parent
3738d2885c
commit
12b36f407d
2 changed files with 8 additions and 8 deletions
|
|
@ -11,12 +11,14 @@ use Stancl\Tenancy\Contracts\Tenant;
|
||||||
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Purge central connection, set Postgres credentials to the tenant's credentials
|
* Set Postgres credentials to the tenant's credentials and use Postgres as the central connection.
|
||||||
* and use Postgres as the central connection.
|
|
||||||
*
|
*
|
||||||
* This bootstrapper is intended to be used with single-database tenancy.
|
* This bootstrapper is intended to be used with Postgres RLS (single-database tenancy).
|
||||||
|
*
|
||||||
|
* @see \Stancl\Tenancy\Commands\CreatePostgresUserForTenants
|
||||||
|
* @see \Stancl\Tenancy\Commands\CreateRLSPoliciesForTenantTables
|
||||||
*/
|
*/
|
||||||
class PostgresSingleDatabaseBootstrapper implements TenancyBootstrapper
|
class PostgresRLSBootstrapper implements TenancyBootstrapper
|
||||||
{
|
{
|
||||||
protected array $originalCentralConnectionConfig;
|
protected array $originalCentralConnectionConfig;
|
||||||
protected array $originalPostgresConfig;
|
protected array $originalPostgresConfig;
|
||||||
|
|
@ -32,8 +34,6 @@ class PostgresSingleDatabaseBootstrapper implements TenancyBootstrapper
|
||||||
public function bootstrap(Tenant $tenant): void
|
public function bootstrap(Tenant $tenant): void
|
||||||
{
|
{
|
||||||
/** @var TenantWithDatabase $tenant */
|
/** @var TenantWithDatabase $tenant */
|
||||||
$this->database->purge('central');
|
|
||||||
|
|
||||||
$this->config->set('database.connections.pgsql.username', $tenant->database()->getUsername() ?? $tenant->getTenantKey());
|
$this->config->set('database.connections.pgsql.username', $tenant->database()->getUsername() ?? $tenant->getTenantKey());
|
||||||
$this->config->set('database.connections.pgsql.password', $tenant->database()->getPassword() ?? 'password');
|
$this->config->set('database.connections.pgsql.password', $tenant->database()->getPassword() ?? 'password');
|
||||||
|
|
||||||
|
|
@ -17,7 +17,7 @@ use Stancl\Tenancy\Jobs\DeleteTenantsPostgresUser;
|
||||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||||
use Stancl\Tenancy\Jobs\CreatePostgresUserForTenant;
|
use Stancl\Tenancy\Jobs\CreatePostgresUserForTenant;
|
||||||
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
||||||
use Stancl\Tenancy\Bootstrappers\Integrations\PostgresSingleDatabaseBootstrapper;
|
use Stancl\Tenancy\Bootstrappers\Integrations\PostgresRLSBootstrapper;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
DB::purge('central');
|
DB::purge('central');
|
||||||
|
|
@ -25,7 +25,7 @@ beforeEach(function () {
|
||||||
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
|
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
|
||||||
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
|
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
|
||||||
|
|
||||||
config(['tenancy.bootstrappers' => [PostgresSingleDatabaseBootstrapper::class]]);
|
config(['tenancy.bootstrappers' => [PostgresRLSBootstrapper::class]]);
|
||||||
config(['database.connections.central' => config('database.connections.pgsql')]);
|
config(['database.connections.central' => config('database.connections.pgsql')]);
|
||||||
config(['tenancy.models.tenant_key_column' => 'tenant_id']);
|
config(['tenancy.models.tenant_key_column' => 'tenant_id']);
|
||||||
config(['tenancy.models.tenant' => $tenantClass = Tenant::class]);
|
config(['tenancy.models.tenant' => $tenantClass = Tenant::class]);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue