From 9520cbc811e3859a6aa30526b0e52e0b5ac80bf7 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Fri, 18 Nov 2022 15:58:04 +0100 Subject: [PATCH] Only delete tenants in MigrateFreshOverride if the tenants table exists (#1007) * Don't drop tenant databases on `migrate:fresh` if the tenants table doesn't exist * Fix code style (php-cs-fixer) Co-authored-by: PHP CS Fixer --- src/Commands/MigrateFreshOverride.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Commands/MigrateFreshOverride.php b/src/Commands/MigrateFreshOverride.php index 88e9e21e..f2fd70b0 100644 --- a/src/Commands/MigrateFreshOverride.php +++ b/src/Commands/MigrateFreshOverride.php @@ -5,13 +5,18 @@ declare(strict_types=1); namespace Stancl\Tenancy\Commands; use Illuminate\Database\Console\Migrations\FreshCommand; +use Illuminate\Support\Facades\Schema; class MigrateFreshOverride extends FreshCommand { public function handle() { if (config('tenancy.database.drop_tenant_databases_on_migrate_fresh')) { - tenancy()->model()::cursor()->each->delete(); + $tenantModel = tenancy()->model(); + + if (Schema::hasTable($tenantModel->getTable())) { + $tenantModel::cursor()->each->delete(); + } } return parent::handle();