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

Add skip-failing option to the Migrate command (#945)

* Add and test Migrate command's skip-failing option

* Improve naming

* Move migration event dispatching inside try block

* Change test name

* Fix skip-failing test

* Use QueryException instead of Exception

* Correct TenantDatabaseDoesNotExistException import

* Correct test

* Check for the the testing env in DB bootstrapper

* Correct the Migrate command

* Fix code style (php-cs-fixer)

* add docs todo

* Add QueryException to the Migrat command try/catch

* Return status codes in Migrate

* Fix code style (php-cs-fixer)

* Add test for not stopping tenants:migrate after the first failure

* Update Migrate command

* Fix code style (php-cs-fixer)

* Fix code style (php-cs-fixer)

* Use `getTenants()`

* Use withtenantDatabases where needed

* Add withTenantDatabases to test

---------

Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
This commit is contained in:
lukinovec 2023-02-01 06:55:26 +01:00 committed by GitHub
parent f741f44527
commit 342c67fe02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 95 additions and 20 deletions

View file

@ -3,23 +3,23 @@
declare(strict_types=1);
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Spatie\Valuestore\Valuestore;
use Illuminate\Support\Facades\DB;
use Stancl\Tenancy\Tests\Etc\User;
use Stancl\JobPipeline\JobPipeline;
use Stancl\Tenancy\Tests\Etc\Tenant;
use Illuminate\Support\Facades\Event;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Schema;
use Stancl\Tenancy\Events\TenancyEnded;
use Stancl\Tenancy\Jobs\CreateDatabase;
use Illuminate\Queue\InteractsWithQueue;
use Stancl\Tenancy\Events\TenantCreated;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Queue\Events\JobProcessing;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Stancl\Tenancy\Events\TenancyInitialized;
use Stancl\Tenancy\Listeners\BootstrapTenancy;
use Stancl\Tenancy\Listeners\RevertToCentralContext;
@ -48,6 +48,8 @@ afterEach(function () {
});
test('tenant id is passed to tenant queues', function () {
withTenantDatabases();
config(['queue.default' => 'sync']);
$tenant = Tenant::create();
@ -64,6 +66,8 @@ test('tenant id is passed to tenant queues', function () {
});
test('tenant id is not passed to central queues', function () {
withTenantDatabases();
$tenant = Tenant::create();
tenancy()->initialize($tenant);
@ -156,6 +160,8 @@ test('tenancy is initialized when retrying jobs', function (bool $shouldEndTenan
})->with([true, false]);
test('the tenant used by the job doesnt change when the current tenant changes', function () {
withTenantDatabases();
$tenant1 = Tenant::create([
'id' => 'acme',
]);
@ -217,13 +223,6 @@ function withUsers()
});
}
function withTenantDatabases()
{
Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) {
return $event->tenant;
})->toListener());
}
class TestJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;