1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 09:54:05 +00:00

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.
This commit is contained in:
masiorama 2022-02-22 11:22:52 +01:00 committed by GitHub
parent 5b9b384526
commit 9f83a65f22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,
]));