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

Migrate Refresh

This commit is contained in:
Hothaifa Jaber 2022-11-22 22:50:21 +03:00
parent 84a3287799
commit eed1def819
2 changed files with 52 additions and 0 deletions

View file

@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
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 MigrateRefresh extends Command
{
use HasATenantsOption, DealsWithMigrations;
/**
* The console command description.
*
* @var string
*/
protected $description = 'Reset and re-run all migrations';
public function __construct()
{
parent::__construct();
$this->addOption('--path', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The path(s) to the migrations files to be executed', null);
$this->setName('tenants:migrate-refresh');
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
$this->info('Rolling back migrations.');
$this->call('migrate:refresh', array_filter([
'--database' => 'tenant',
'--path' => $this->option('path'),
'--force' => true,
]));
});
$this->info('Done.');
}
}

View file

@ -90,6 +90,7 @@ class TenancyServiceProvider extends ServiceProvider
Commands\Rollback::class,
Commands\TenantList::class,
Commands\MigrateFresh::class,
Commands\MigrateRefresh::class,
]);
$this->publishes([