mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 12:04:03 +00:00
Use "Postgres user" instead of "Postgres role"
This commit is contained in:
parent
26eafd30ba
commit
e000386d1f
3 changed files with 9 additions and 9 deletions
|
|
@ -30,7 +30,7 @@ class TenancyServiceProvider extends ServiceProvider
|
||||||
// Jobs\SeedDatabase::class,
|
// Jobs\SeedDatabase::class,
|
||||||
|
|
||||||
// Jobs\CreateStorageSymlinks::class,
|
// Jobs\CreateStorageSymlinks::class,
|
||||||
// Jobs\CreatePostgresRoleForTenant::class,
|
// Jobs\CreatePostgresUserForTenant::class,
|
||||||
|
|
||||||
// Your own jobs to prepare the tenant.
|
// Your own jobs to prepare the tenant.
|
||||||
// Provision API keys, create S3 buckets, anything you want!
|
// Provision API keys, create S3 buckets, anything you want!
|
||||||
|
|
@ -56,7 +56,7 @@ class TenancyServiceProvider extends ServiceProvider
|
||||||
Events\TenantDeleted::class => [
|
Events\TenantDeleted::class => [
|
||||||
JobPipeline::make([
|
JobPipeline::make([
|
||||||
Jobs\DeleteDatabase::class,
|
Jobs\DeleteDatabase::class,
|
||||||
// Jobs\DeleteTenantsPostgresRole::class,
|
// Jobs\DeleteTenantsPostgresUser::class,
|
||||||
// Jobs\RemoveStorageSymlinks::class,
|
// Jobs\RemoveStorageSymlinks::class,
|
||||||
])->send(function (Events\TenantDeleted $event) {
|
])->send(function (Events\TenantDeleted $event) {
|
||||||
return $event->tenant;
|
return $event->tenant;
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
||||||
|
|
||||||
class CreatePostgresRoleForTenant implements ShouldQueue
|
class CreatePostgresUserForTenant implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
|
@ -39,9 +39,9 @@ class CreatePostgresRoleForTenant implements ShouldQueue
|
||||||
$password = $this->tenant->database()->getPassword() ?? 'password';
|
$password = $this->tenant->database()->getPassword() ?? 'password';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DB::statement("CREATE ROLE \"$name\" LOGIN PASSWORD '$password';");
|
DB::statement("CREATE USER \"$name\" LOGIN PASSWORD '$password';");
|
||||||
} catch (QueryException $exception) {
|
} catch (QueryException $exception) {
|
||||||
// Skip creating Postgres role if it already exists
|
// Skip creating Postgres user if it already exists
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -14,7 +14,7 @@ use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
||||||
|
|
||||||
class DeleteTenantsPostgresRole implements ShouldQueue
|
class DeleteTenantsPostgresUser implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
|
@ -37,12 +37,12 @@ class DeleteTenantsPostgresRole implements ShouldQueue
|
||||||
{
|
{
|
||||||
$tenantKey = $this->tenant->getTenantKey();
|
$tenantKey = $this->tenant->getTenantKey();
|
||||||
|
|
||||||
// Revoke all permissions of a role before dropping it
|
// Revoke all permissions of a Postgres user before dropping it
|
||||||
try {
|
try {
|
||||||
DB::statement("DROP OWNED BY \"{$tenantKey}\";");
|
DB::statement("DROP OWNED BY \"{$tenantKey}\";");
|
||||||
DB::statement("DROP ROLE \"{$tenantKey}\";");
|
DB::statement("DROP USER \"{$tenantKey}\";");
|
||||||
} catch (QueryException $exception) {
|
} catch (QueryException $exception) {
|
||||||
// Skip dropping permissions if the role doesn't exist
|
// Skip dropping permissions if the user doesn't exist
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue