mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 10:14:04 +00:00
migrate-fresh first draft
This commit is contained in:
parent
50cf677034
commit
5907099303
1 changed files with 62 additions and 0 deletions
62
src/Commands/MigrateFresh.php
Normal file
62
src/Commands/MigrateFresh.php
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue