1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 14:14:03 +00:00
tenancy/src/Commands/MigrateFresh.php

45 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Commands;
use Illuminate\Console\Command;
use Stancl\Tenancy\Concerns\HasATenantsOption;
use Symfony\Component\Console\Input\InputOption;
final class MigrateFresh extends Command
{
use HasATenantsOption;
protected $description = 'Drop all tables and re-run all migrations for tenant(s)';
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');
}
public function handle(): void
{
tenancy()->runForMultiple($this->getTenants(), function ($tenant) {
$this->info('Dropping tables.');
$this->call('db:wipe', array_filter([
'--database' => 'tenant',
'--drop-views' => $this->option('drop-views'),
'--force' => true,
]));
$this->info('Migrating.');
$this->callSilent('tenants:migrate', [
'--tenants' => [$tenant->getTenantKey()],
'--force' => true,
]);
});
$this->info('Done.');
}
}