Closed scramatte closed 1 year ago
@abrardev99 Try to reproduce this tomorrow (using boilerplate code as mentioned in the reproduction steps)
edit: probably can be postponed, likely isn't a bug in the package
I've just do it, with just boilerplate and occur the same issue. It looks that the problem occurs when you create tenant using Nova4.
Ah I see the issue in the original comment now. I don't think the schema manager has anything to do with this. It's just Nova running the creation logic inside a DB transaction which doesn't let you create databases in Laravel 8/9+. I'd search the issue tracker & our Discord servers for this, it's been discussed in the past.
Nova doesn't let to create database but using schema it neither works. Moreover, queued job, ran out of Nova, so it should be ok isn't it?
I've just try back with schema and queue job and nothing. Same error ...
Can you send me references , I've searched myself on issue tracker and discord server but I haven't been able to found anything
Working solution based on https://github.com/laravel/nova-issues/issues/180#issuecomment-433493057
class CreateTenant extends Action implements ShouldQueue
{
use InteractsWithQueue;
use Queueable;
public $withoutActionEvents = true;
public $confirmButtonText = 'Create Tenant';
/**
* @throws Throwable
*/
public function handle(ActionFields $fields): void
{
DB::commit();
$tenant = Tenant::create(['name' => $fields['name']]);
$tenant->domains()->create(['domain' => $fields['domain']]);
}
public function fields(NovaRequest $request): array
{
return [
Text::make('Project Name', 'name')
->rules(['required', 'string', 'max:30', 'unique:tenants,name'])
,
Text::make('First Domain', 'domain')
->rules(['required', 'string', 'unique:domains,domain'])
,
];
}
}
Bug description
Hello,
Jobs\MigrateDatabase fails using driver TenantDatabaseManagers\PostgreSQLSchemaManager::class
If I migrate tenants table with artisan, it works. It only fails when on Events\TenantCreated jobs
I've tested tooo with the other pgsql driver TenantDatabaseManagers\PostgreSQLDatabaseManager::class And I'm unable to create database. Note that I'm using postgres user so, it should let me create anything!
So, Ive come back to TenantDatabaseManagers\PostgreSQLSchemaManager driver as at least it let me create the database.
I've take a look to Jobs\MigrateDatabase code and I've seen. that exec Artisan command. So I've tried to exec the same command on shell and it works well.
I've dumped baseConfig from TenantDatabaseManagers\PostgreSQLSchemaManager driver when Jobs\MigrateDatabase is running. And It looks fine as search_path is set to the correct schema.
I don't think that is permissions issue as I'm using postgres user and moreover it works from console. Any ideas? I can't progress on my project due to this issue.
Thank you for the help
Regards
Steps to reproduce
Setup laravel tenancy using boilerplate and set tenant database driver to TenantDatabaseManagers\PostgreSQLSchemaManager::class
You must enable Jobs\MigrateDatabase into
app/Providers/TenancyServiceProvider.php
tooExpected behavior
Job should runs without error and migrate all tenants tables
Laravel version
9.19
stancl/tenancy version
3.6