From 9f83a65f22c79846d88f0e1bfea8f13f466984f2 Mon Sep 17 00:00:00 2001 From: masiorama Date: Tue, 22 Feb 2022 11:22:52 +0100 Subject: [PATCH] Optionally handle drop of table views on MigrateFresh @stancl I managed to make the modification discussed here #811 Afaik (and I can understand) this is the easiest way to handle it, but I'm open to discuss. --- src/Commands/MigrateFresh.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Commands/MigrateFresh.php b/src/Commands/MigrateFresh.php index f50e2f5f..5f893e20 100644 --- a/src/Commands/MigrateFresh.php +++ b/src/Commands/MigrateFresh.php @@ -7,6 +7,7 @@ namespace Stancl\Tenancy\Commands; use Illuminate\Console\Command; use Stancl\Tenancy\Concerns\DealsWithMigrations; use Stancl\Tenancy\Concerns\HasATenantsOption; +use Symfony\Component\Console\Input\InputOption; final class MigrateFresh extends Command { @@ -22,6 +23,8 @@ final class MigrateFresh extends Command public function __construct() { parent::__construct(); + + $this->addOption('--drop-views', null, InputOption::VALUE_NONE, 'Drop views along with tenant tables.', null); $this->setName('tenants:migrate-fresh'); } @@ -33,10 +36,13 @@ final class MigrateFresh extends Command */ public function handle() { - tenancy()->runForMultiple($this->option('tenants'), function ($tenant) { + $dropViewsFlag = $this->option('drop-views'); + + tenancy()->runForMultiple($this->option('tenants'), function ($tenant) use ($dropViewsFlag) { $this->info('Dropping tables.'); $this->call('db:wipe', array_filter([ '--database' => 'tenant', + '--drop-views' => $dropViewsFlag, '--force' => true, ]));