1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 14:14:04 +00:00

[4.x] Use --database in tenants:migrate as the template connection (#1386)

* Make the `--database` option passed to `tenants:migrate` use the passed connection as the tenant connection template

* Reset template connection regardless of process count

---------

Co-authored-by: Samuel Štancl <samuel@archte.ch>
This commit is contained in:
lukinovec 2025-08-25 15:57:15 +02:00 committed by GitHub
parent d9f3525700
commit 3b42c9e20c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 71 additions and 5 deletions

View file

@ -51,13 +51,24 @@ class Migrate extends MigrateCommand
return 1;
}
if ($this->getProcesses() > 1) {
return $this->runConcurrently($this->getTenantChunks()->map(function ($chunk) {
return $this->getTenants($chunk);
}));
$originalTemplateConnection = config('tenancy.database.template_tenant_connection');
if ($database = $this->input->getOption('database')) {
config(['tenancy.database.template_tenant_connection' => $database]);
}
return $this->migrateTenants($this->getTenants()) ? 0 : 1;
if ($this->getProcesses() > 1) {
$code = $this->runConcurrently($this->getTenantChunks()->map(function ($chunk) {
return $this->getTenants($chunk);
}));
} else {
$code = $this->migrateTenants($this->getTenants()) ? 0 : 1;
}
// Reset the template tenant connection to the original one
config(['tenancy.database.template_tenant_connection' => $originalTemplateConnection]);
return $code;
}
protected function childHandle(mixed ...$args): bool