mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 09:34:05 +00:00
always register MigrateFreshOverride
This commit is contained in:
parent
912f9a964d
commit
607ea723e5
3 changed files with 11 additions and 43 deletions
|
|
@ -10,7 +10,9 @@ class MigrateFreshOverride extends FreshCommand
|
|||
{
|
||||
public function handle()
|
||||
{
|
||||
tenancy()->model()::all()->each->delete();
|
||||
if (config('tenancy.database.drop_tenant_databases_on_migrate_fresh')) {
|
||||
tenancy()->model()::cursor()->each->delete();
|
||||
}
|
||||
|
||||
return parent::handle();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,12 +91,8 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
Commands\Up::class,
|
||||
]);
|
||||
|
||||
$this->app->extend(FreshCommand::class, function (FreshCommand $originalCommand) {
|
||||
if ($this->app['config']['tenancy.database.drop_tenant_databases_on_migrate_fresh']) {
|
||||
return new Commands\MigrateFreshOverride;
|
||||
}
|
||||
|
||||
return $originalCommand;
|
||||
$this->app->extend(FreshCommand::class, function () {
|
||||
return new Commands\MigrateFreshOverride;
|
||||
});
|
||||
|
||||
$this->publishes([
|
||||
|
|
|
|||
|
|
@ -18,16 +18,11 @@ use Stancl\Tenancy\Events\TenantCreated;
|
|||
use Stancl\Tenancy\Events\TenantDeleted;
|
||||
use Stancl\Tenancy\Tests\Etc\TestSeeder;
|
||||
use Stancl\Tenancy\Events\DeletingTenant;
|
||||
use Stancl\Tenancy\TenancyServiceProvider;
|
||||
use Stancl\Tenancy\Tests\Etc\ExampleSeeder;
|
||||
use Stancl\Tenancy\Events\TenancyInitialized;
|
||||
use Illuminate\Console\ContainerCommandLoader;
|
||||
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
||||
use Illuminate\Database\Console\Migrations\FreshCommand;
|
||||
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
|
||||
use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
|
||||
|
||||
|
||||
beforeEach(function () {
|
||||
|
|
@ -276,9 +271,8 @@ test('run command works when sub command asks questions and accepts arguments',
|
|||
expect($user->email)->toBe('email@localhost');
|
||||
});
|
||||
|
||||
test('migrate fresh command only deletes tenant databases if drop_tenant_databases_on_migrate_fresh is true', function() {
|
||||
Event::listen(
|
||||
DeletingTenant::class,
|
||||
test('migrate fresh command only deletes tenant databases if drop_tenant_databases_on_migrate_fresh is true', function (bool $dropTenantDBsOnMigrateFresh) {
|
||||
Event::listen(DeletingTenant::class,
|
||||
JobPipeline::make([DeleteDomains::class])->send(function (DeletingTenant $event) {
|
||||
return $event->tenant;
|
||||
})->shouldBeQueued(false)->toListener()
|
||||
|
|
@ -291,9 +285,8 @@ test('migrate fresh command only deletes tenant databases if drop_tenant_databas
|
|||
})->shouldBeQueued(false)->toListener()
|
||||
);
|
||||
|
||||
|
||||
config(['tenancy.database.drop_tenant_databases_on_migrate_fresh' => false]);
|
||||
app()->forgetInstance(FreshCommand::class);
|
||||
config(['tenancy.database.drop_tenant_databases_on_migrate_fresh' => $dropTenantDBsOnMigrateFresh]);
|
||||
$shouldHaveDBAfterMigrateFresh = ! $dropTenantDBsOnMigrateFresh;
|
||||
|
||||
/** @var Tenant[] $tenants */
|
||||
$tenants = [
|
||||
|
|
@ -315,32 +308,9 @@ test('migrate fresh command only deletes tenant databases if drop_tenant_databas
|
|||
]);
|
||||
|
||||
foreach ($tenants as $tenant) {
|
||||
expect($tenantHasDatabase($tenant))->toBeTrue();
|
||||
expect($tenantHasDatabase($tenant))->toBe($shouldHaveDBAfterMigrateFresh);
|
||||
}
|
||||
|
||||
config(['tenancy.database.drop_tenant_databases_on_migrate_fresh' => true]);
|
||||
app()->forgetInstance(FreshCommand::class);
|
||||
|
||||
$tenants = [
|
||||
Tenant::create(),
|
||||
Tenant::create(),
|
||||
Tenant::create(),
|
||||
];
|
||||
|
||||
foreach ($tenants as $tenant) {
|
||||
expect($tenantHasDatabase($tenant))->toBeTrue();
|
||||
}
|
||||
|
||||
pest()->artisan('migrate:fresh', [
|
||||
'--force' => true,
|
||||
'--path' => __DIR__ . '/../assets/migrations',
|
||||
'--realpath' => true,
|
||||
]);
|
||||
|
||||
foreach ($tenants as $tenant) {
|
||||
expect($tenantHasDatabase($tenant))->toBeFalse();
|
||||
}
|
||||
});
|
||||
})->with([true, false]);
|
||||
|
||||
// todo@tests
|
||||
function runCommandWorks(): void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue