Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
65 righe
1.8 KiB
65 righe
1.8 KiB
<?php |
|
|
|
namespace App\Console\Commands\Database\Tenant; |
|
|
|
use App\Models\Main\Tenant; |
|
use Illuminate\Console\Command; |
|
|
|
class MigrateCommand extends Command |
|
{ |
|
/** |
|
* The name and signature of the console command. |
|
* |
|
* @var string |
|
*/ |
|
protected $signature = 'tenantdb:migrate |
|
{--force : Force the operation to run when in production} |
|
{--pretend : Dump the SQL queries that would be run} |
|
{--step : Force the migrations to be run so they can be rolled back individually}'; |
|
|
|
/** |
|
* The console command description. |
|
* |
|
* @var string |
|
*/ |
|
protected $description = 'Run main database migrations'; |
|
|
|
/** |
|
* Create a new command instance. |
|
* |
|
* @return void |
|
*/ |
|
public function __construct() |
|
{ |
|
parent::__construct(); |
|
} |
|
|
|
/** |
|
* Execute the console command. |
|
* |
|
* @return int |
|
*/ |
|
public function handle() |
|
{ |
|
setup_db_connection(); |
|
$options = ['--path' => 'database/migrations/tenant', '--database' => 'mysql-tenant']; |
|
if(!empty( $this->option('force'))) { $options['--force'] = true; } |
|
if(!empty( $this->option('step'))) { $options['--step'] = true; } |
|
if(!empty( $this->option('pretend'))) { $options['--pretend'] = true; } |
|
|
|
Tenant::whereNotNull('dominio')->where('dominio','<>','N')->where('db','S')->chunk(10, function($tenants) use ($options) { |
|
|
|
foreach($tenants as $tenant) { |
|
|
|
config(['database.connections.mysql-tenant.database' => config('json.prefix_db') . "_ente{$tenant->codice}"]); |
|
\Illuminate\Support\Facades\DB::purge('mysql-tenant'); |
|
|
|
$this->info("Processing: {$tenant->denominazione}"); |
|
$this->call('migrate', $options); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
}
|
|
|