1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-17 05:44:04 +00:00
tenancy/src/Commands/Migrate.php
Samuel Štancl 7389f44de9
[2.2.0] Use Tenant Run in console commands (#205)
* Utilize Tenant Run in commands

* Apply fixes from StyleCI
2019-10-27 20:50:49 +01:00

63 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Commands;
use Illuminate\Console\Command;
use Illuminate\Database\Console\Migrations\MigrateCommand;
use Illuminate\Database\Migrations\Migrator;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Traits\DealsWithMigrations;
use Stancl\Tenancy\Traits\HasATenantsOption;
class Migrate extends MigrateCommand
{
use HasATenantsOption, DealsWithMigrations;
protected $database;
/**
* The console command description.
*
* @var string
*/
protected $description = 'Run migrations for tenant(s)';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct(Migrator $migrator, DatabaseManager $database)
{
parent::__construct($migrator);
$this->database = $database;
$this->setName('tenants:migrate');
$this->specifyParameters();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
if (! $this->confirmToProceed()) {
return;
}
tenancy()->all($this->option('tenants'))->each(function ($tenant) {
$this->line("Tenant: {$tenant['id']}");
$this->input->setOption('database', $tenant->getConnectionName());
$tenant->run(function () {
// Migrate
parent::handle();
});
});
}
}