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

Correct the Migrate command

This commit is contained in:
lukinovec 2022-10-03 14:00:27 +02:00
parent 343de54b40
commit 737454a6a9

View file

@ -5,14 +5,14 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Commands; namespace Stancl\Tenancy\Commands;
use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Database\Console\Migrations\MigrateCommand; use Stancl\Tenancy\Events\DatabaseMigrated;
use Illuminate\Database\Migrations\Migrator; use Illuminate\Database\Migrations\Migrator;
use Illuminate\Database\QueryException; use Stancl\Tenancy\Events\MigratingDatabase;
use Stancl\Tenancy\Concerns\HasATenantsOption;
use Stancl\Tenancy\Concerns\DealsWithMigrations; use Stancl\Tenancy\Concerns\DealsWithMigrations;
use Stancl\Tenancy\Concerns\ExtendsLaravelCommand; use Stancl\Tenancy\Concerns\ExtendsLaravelCommand;
use Stancl\Tenancy\Concerns\HasATenantsOption; use Illuminate\Database\Console\Migrations\MigrateCommand;
use Stancl\Tenancy\Events\DatabaseMigrated; use Stancl\Tenancy\Database\Exceptions\TenantDatabaseDoesNotExistException;
use Stancl\Tenancy\Events\MigratingDatabase;
class Migrate extends MigrateCommand class Migrate extends MigrateCommand
{ {
@ -49,20 +49,20 @@ class Migrate extends MigrateCommand
return; return;
} }
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) { try {
$this->line("Tenant: {$tenant->getTenantKey()}"); tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
$this->line("Tenant: {$tenant->getTenantKey()}");
try {
event(new MigratingDatabase($tenant)); event(new MigratingDatabase($tenant));
// Migrate // Migrate
parent::handle(); parent::handle();
event(new DatabaseMigrated($tenant)); event(new DatabaseMigrated($tenant));
} catch (QueryException $th) { });
if (! $this->option('skip-failing')) { } catch (TenantDatabaseDoesNotExistException $th) {
throw $th; if (! $this->option('skip-failing')) {
} throw $th;
} }
}); }
} }
} }