MigrateTenants.php 930 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Services\MigrationService;
  5. class MigrateTenants extends Command
  6. {
  7. protected $signature = 'migrate:tenants {--rollback} {--step=1}';
  8. protected $description = 'Run migrations on all tenant databases';
  9. public function handle(MigrationService $migrationService)
  10. {
  11. if ($this->option('rollback')) {
  12. $result = $migrationService->rollbackTenantMigrations($this->option('step'));
  13. } else {
  14. $result = $migrationService->runTenantMigrations();
  15. }
  16. $this->info($result['message']);
  17. if (!empty($result['results'])) {
  18. $tableData = [];
  19. foreach ($result['results'] as $r) {
  20. $tableData[] = [$r['tenant'], $r['status'], $r['message']];
  21. }
  22. $this->table(['Tenant Database', 'Status', 'Message'], $tableData);
  23. }
  24. }
  25. }