1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-05-07 01:04:03 +00:00

Enhance tenant migration command to support parallel execution

- Added a `--parallel` option to the Migrate command for concurrent tenant migrations.
- Introduced a `parallel-batch-size` option to control the number of concurrent migrations.
- Implemented a new method `runParallel` to handle parallel migrations.
- Updated the `handle` method to initiate parallel migrations when the option is set.
- Added tests to verify the functionality of the parallel migration option.
This commit is contained in:
khaledSayed93 2026-03-28 23:09:42 +02:00
parent ab64f4599d
commit 3498a3f9c2
3 changed files with 219 additions and 10 deletions

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Tests;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Concurrency;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Schema;
@ -92,6 +93,34 @@ class CommandsTest extends TestCase
$this->assertTrue(Schema::hasTable('users'));
}
#[Test]
public function migrate_command_works_with_parallel_option()
{
if (! class_exists(Concurrency::class)) {
$this->markTestSkipped('Parallel tenant migrations require the Concurrency facade (Laravel 11+).');
}
config(['concurrency.default' => 'sync']);
$tenant1 = Tenant::create();
$tenant2 = Tenant::create();
$this->assertFalse(Schema::hasTable('users'));
Artisan::call('tenants:migrate', [
'--parallel' => true,
]);
$this->assertFalse(Schema::hasTable('users'));
tenancy()->initialize($tenant1);
$this->assertTrue(Schema::hasTable('users'));
tenancy()->end();
tenancy()->initialize($tenant2);
$this->assertTrue(Schema::hasTable('users'));
}
#[Test]
public function rollback_command_works()
{