diff --git a/src/Commands/Migrate.php b/src/Commands/Migrate.php index d9ba4938..279a371b 100644 --- a/src/Commands/Migrate.php +++ b/src/Commands/Migrate.php @@ -49,21 +49,15 @@ class Migrate extends MigrateCommand return; } - $originalTenant = tenancy()->getTenant(); tenancy()->all($this->option('tenants'))->each(function ($tenant) { $this->line("Tenant: {$tenant['id']}"); $this->input->setOption('database', $tenant->getConnectionName()); - tenancy()->initialize($tenant); - // Migrate - parent::handle(); - - tenancy()->endTenancy(); + $tenant->run(function () { + // Migrate + parent::handle(); + }); }); - - if ($originalTenant) { - tenancy()->initialize($originalTenant); - } } } diff --git a/src/Commands/MigrateFresh.php b/src/Commands/MigrateFresh.php index 6a31e888..34493c3f 100644 --- a/src/Commands/MigrateFresh.php +++ b/src/Commands/MigrateFresh.php @@ -33,30 +33,23 @@ final class MigrateFresh extends Command */ public function handle() { - $originalTenant = tenancy()->getTenant(); - $this->info('Dropping tables.'); - tenancy()->all($this->option('tenants'))->each(function ($tenant) { $this->line("Tenant: {$tenant->id}"); - tenancy()->initialize($tenant); + $tenant->run(function ($tenant) { + $this->info('Dropping tables.'); + $this->call('db:wipe', array_filter([ + '--database' => $tenant->getConnectionName(), + '--force' => true, + ])); - $this->call('db:wipe', array_filter([ - '--database' => $tenant->getConnectionName(), - '--force' => true, - ])); - - $this->call('tenants:migrate', [ - '--tenants' => [$tenant->id], - ]); - - tenancy()->end(); + $this->info('Migrating.'); + $this->callSilent('tenants:migrate', [ + '--tenants' => [$tenant->id], + ]); + }); }); $this->info('Done.'); - - if ($originalTenant) { - tenancy()->initialize($originalTenant); - } } } diff --git a/src/Commands/Rollback.php b/src/Commands/Rollback.php index b9168bf7..eee99ddd 100644 --- a/src/Commands/Rollback.php +++ b/src/Commands/Rollback.php @@ -49,21 +49,15 @@ class Rollback extends RollbackCommand return; } - $originalTenant = tenancy()->getTenant(); tenancy()->all($this->option('tenants'))->each(function ($tenant) { $this->line("Tenant: {$tenant['id']}"); $this->input->setOption('database', $tenant->getConnectionName()); - tenancy()->initialize($tenant); - // Migrate - parent::handle(); - - tenancy()->endTenancy(); + $tenant->run(function () { + // Rollback + parent::handle(); + }); }); - - if ($originalTenant) { - tenancy()->initialize($originalTenant); - } } } diff --git a/src/Commands/Seed.php b/src/Commands/Seed.php index 61630408..c1f37150 100644 --- a/src/Commands/Seed.php +++ b/src/Commands/Seed.php @@ -47,21 +47,15 @@ class Seed extends SeedCommand return; } - $originalTenant = tenancy()->getTenant(); tenancy()->all($this->option('tenants'))->each(function ($tenant) { $this->line("Tenant: {$tenant['id']}"); $this->input->setOption('database', $tenant->getConnectionName()); - tenancy()->initialize($tenant); - // Seed - parent::handle(); - - tenancy()->endTenancy(); + $tenant->run(function () { + // Seed + parent::handle(); + }); }); - - if ($originalTenant) { - tenancy()->initialize($originalTenant); - } } }