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

migrate-fresh first draft

This commit is contained in:
Samuel Štancl 2019-09-29 12:12:32 +02:00
parent 50cf677034
commit 5907099303

View file

@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Commands;
use Illuminate\Console\Command;
use Stancl\Tenancy\Traits\DealsWithMigrations;
use Stancl\Tenancy\Traits\HasATenantsOption;
class MigrateFresh extends Command
{
use HasATenantsOption, DealsWithMigrations;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'tenants:migrate-fresh';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Drop all tables and re-run all migrations for tenant(s)';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$originalTenant = tenancy()->getTenant();
$this->info('Dropping tables.');
tenancy()->all($this->option('tenants'))->each(function ($tenant) {
$this->line("Tenant: {$tenant->id}");
tenancy()->initialize($tenant);
$this->call('db:wipe', [
'--database' => $tenant->getDatabaseName(),
'--force' => true,
]);
$this->call('tenants:migrate', [
'--tenants' => [$tenant->id],
]);
tenancy()->end();
});
$this->info('Done.');
if ($originalTenant) {
tenancy()->initialize($originalTenant);
}
}
}