1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 06:54:05 +00:00

Use "Postgres user" instead of "Postgres role"

This commit is contained in:
lukinovec 2023-02-15 11:02:53 +01:00
parent 26eafd30ba
commit e000386d1f
3 changed files with 9 additions and 9 deletions

View file

@ -30,7 +30,7 @@ class TenancyServiceProvider extends ServiceProvider
// Jobs\SeedDatabase::class,
// Jobs\CreateStorageSymlinks::class,
// Jobs\CreatePostgresRoleForTenant::class,
// Jobs\CreatePostgresUserForTenant::class,
// Your own jobs to prepare the tenant.
// Provision API keys, create S3 buckets, anything you want!
@ -56,7 +56,7 @@ class TenancyServiceProvider extends ServiceProvider
Events\TenantDeleted::class => [
JobPipeline::make([
Jobs\DeleteDatabase::class,
// Jobs\DeleteTenantsPostgresRole::class,
// Jobs\DeleteTenantsPostgresUser::class,
// Jobs\RemoveStorageSymlinks::class,
])->send(function (Events\TenantDeleted $event) {
return $event->tenant;

View file

@ -14,7 +14,7 @@ use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
class CreatePostgresRoleForTenant implements ShouldQueue
class CreatePostgresUserForTenant implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
@ -39,9 +39,9 @@ class CreatePostgresRoleForTenant implements ShouldQueue
$password = $this->tenant->database()->getPassword() ?? 'password';
try {
DB::statement("CREATE ROLE \"$name\" LOGIN PASSWORD '$password';");
DB::statement("CREATE USER \"$name\" LOGIN PASSWORD '$password';");
} catch (QueryException $exception) {
// Skip creating Postgres role if it already exists
// Skip creating Postgres user if it already exists
}
}
}

View file

@ -14,7 +14,7 @@ use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
class DeleteTenantsPostgresRole implements ShouldQueue
class DeleteTenantsPostgresUser implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
@ -37,12 +37,12 @@ class DeleteTenantsPostgresRole implements ShouldQueue
{
$tenantKey = $this->tenant->getTenantKey();
// Revoke all permissions of a role before dropping it
// Revoke all permissions of a Postgres user before dropping it
try {
DB::statement("DROP OWNED BY \"{$tenantKey}\";");
DB::statement("DROP ROLE \"{$tenantKey}\";");
DB::statement("DROP USER \"{$tenantKey}\";");
} catch (QueryException $exception) {
// Skip dropping permissions if the role doesn't exist
// Skip dropping permissions if the user doesn't exist
}
}
}