mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 12:44:02 +00:00
53 lines
1.2 KiB
PHP
53 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Stancl\Tenancy\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Stancl\Tenancy\Contracts\TenantWithDatabase;
|
|
use Stancl\Tenancy\Concerns\DealsWithMigrations;
|
|
use Stancl\Tenancy\Concerns\HasATenantsOption;
|
|
|
|
final class MigrateFresh extends Command
|
|
{
|
|
use HasATenantsOption, DealsWithMigrations;
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Drop all tables and re-run all migrations for tenant(s)';
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
$this->setName('tenants:migrate-fresh');
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
|
|
$this->info('Dropping tables.');
|
|
$this->call('db:wipe', array_filter([
|
|
'--database' => 'tenant',
|
|
'--force' => true,
|
|
]));
|
|
|
|
$this->info('Migrating.');
|
|
$this->callSilent('tenants:migrate', [
|
|
'--tenants' => [$tenant->getTenantKey()],
|
|
'--force' => true,
|
|
]);
|
|
});
|
|
|
|
$this->info('Done.');
|
|
}
|
|
}
|