1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 20:34:03 +00:00

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 <phpcsfixer@example.com>
This commit is contained in:
lukinovec 2022-11-18 15:58:04 +01:00 committed by GitHub
parent 1db2f0913f
commit 9520cbc811
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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();