mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 17:24:03 +00:00
[2.2.0] Use Tenant Run in console commands (#205)
* Utilize Tenant Run in commands * Apply fixes from StyleCI
This commit is contained in:
parent
b4caaaed51
commit
7389f44de9
4 changed files with 23 additions and 48 deletions
|
|
@ -49,21 +49,15 @@ class Migrate extends MigrateCommand
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$originalTenant = tenancy()->getTenant();
|
|
||||||
tenancy()->all($this->option('tenants'))->each(function ($tenant) {
|
tenancy()->all($this->option('tenants'))->each(function ($tenant) {
|
||||||
$this->line("Tenant: {$tenant['id']}");
|
$this->line("Tenant: {$tenant['id']}");
|
||||||
|
|
||||||
$this->input->setOption('database', $tenant->getConnectionName());
|
$this->input->setOption('database', $tenant->getConnectionName());
|
||||||
tenancy()->initialize($tenant);
|
|
||||||
|
|
||||||
|
$tenant->run(function () {
|
||||||
// Migrate
|
// Migrate
|
||||||
parent::handle();
|
parent::handle();
|
||||||
|
|
||||||
tenancy()->endTenancy();
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
if ($originalTenant) {
|
|
||||||
tenancy()->initialize($originalTenant);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,30 +33,23 @@ final class MigrateFresh extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$originalTenant = tenancy()->getTenant();
|
|
||||||
$this->info('Dropping tables.');
|
|
||||||
|
|
||||||
tenancy()->all($this->option('tenants'))->each(function ($tenant) {
|
tenancy()->all($this->option('tenants'))->each(function ($tenant) {
|
||||||
$this->line("Tenant: {$tenant->id}");
|
$this->line("Tenant: {$tenant->id}");
|
||||||
|
|
||||||
tenancy()->initialize($tenant);
|
$tenant->run(function ($tenant) {
|
||||||
|
$this->info('Dropping tables.');
|
||||||
$this->call('db:wipe', array_filter([
|
$this->call('db:wipe', array_filter([
|
||||||
'--database' => $tenant->getConnectionName(),
|
'--database' => $tenant->getConnectionName(),
|
||||||
'--force' => true,
|
'--force' => true,
|
||||||
]));
|
]));
|
||||||
|
|
||||||
$this->call('tenants:migrate', [
|
$this->info('Migrating.');
|
||||||
|
$this->callSilent('tenants:migrate', [
|
||||||
'--tenants' => [$tenant->id],
|
'--tenants' => [$tenant->id],
|
||||||
]);
|
]);
|
||||||
|
});
|
||||||
tenancy()->end();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->info('Done.');
|
$this->info('Done.');
|
||||||
|
|
||||||
if ($originalTenant) {
|
|
||||||
tenancy()->initialize($originalTenant);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,21 +49,15 @@ class Rollback extends RollbackCommand
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$originalTenant = tenancy()->getTenant();
|
|
||||||
tenancy()->all($this->option('tenants'))->each(function ($tenant) {
|
tenancy()->all($this->option('tenants'))->each(function ($tenant) {
|
||||||
$this->line("Tenant: {$tenant['id']}");
|
$this->line("Tenant: {$tenant['id']}");
|
||||||
|
|
||||||
$this->input->setOption('database', $tenant->getConnectionName());
|
$this->input->setOption('database', $tenant->getConnectionName());
|
||||||
tenancy()->initialize($tenant);
|
|
||||||
|
|
||||||
// Migrate
|
$tenant->run(function () {
|
||||||
|
// Rollback
|
||||||
parent::handle();
|
parent::handle();
|
||||||
|
|
||||||
tenancy()->endTenancy();
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
if ($originalTenant) {
|
|
||||||
tenancy()->initialize($originalTenant);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,21 +47,15 @@ class Seed extends SeedCommand
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$originalTenant = tenancy()->getTenant();
|
|
||||||
tenancy()->all($this->option('tenants'))->each(function ($tenant) {
|
tenancy()->all($this->option('tenants'))->each(function ($tenant) {
|
||||||
$this->line("Tenant: {$tenant['id']}");
|
$this->line("Tenant: {$tenant['id']}");
|
||||||
|
|
||||||
$this->input->setOption('database', $tenant->getConnectionName());
|
$this->input->setOption('database', $tenant->getConnectionName());
|
||||||
tenancy()->initialize($tenant);
|
|
||||||
|
|
||||||
|
$tenant->run(function () {
|
||||||
// Seed
|
// Seed
|
||||||
parent::handle();
|
parent::handle();
|
||||||
|
|
||||||
tenancy()->endTenancy();
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
if ($originalTenant) {
|
|
||||||
tenancy()->initialize($originalTenant);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue