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

Merge branch 'master' of github.com:archtechx/tenancy

This commit is contained in:
Samuel Štancl 2025-08-25 17:43:53 +02:00
commit e806825f71
6 changed files with 128 additions and 47 deletions

View file

@ -51,13 +51,24 @@ class Migrate extends MigrateCommand
return 1;
}
if ($this->getProcesses() > 1) {
return $this->runConcurrently($this->getTenantChunks()->map(function ($chunk) {
return $this->getTenants($chunk);
}));
$originalTemplateConnection = config('tenancy.database.template_tenant_connection');
if ($database = $this->input->getOption('database')) {
config(['tenancy.database.template_tenant_connection' => $database]);
}
return $this->migrateTenants($this->getTenants()) ? 0 : 1;
if ($this->getProcesses() > 1) {
$code = $this->runConcurrently($this->getTenantChunks()->map(function ($chunk) {
return $this->getTenants($chunk);
}));
} else {
$code = $this->migrateTenants($this->getTenants()) ? 0 : 1;
}
// Reset the template tenant connection to the original one
config(['tenancy.database.template_tenant_connection' => $originalTemplateConnection]);
return $code;
}
protected function childHandle(mixed ...$args): bool

View file

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Commands;
use Illuminate\Console\ConfirmableTrait;
use Illuminate\Database\Console\Migrations\BaseCommand;
use Illuminate\Database\QueryException;
use Illuminate\Support\LazyCollection;
@ -17,7 +18,7 @@ use Symfony\Component\Console\Output\OutputInterface as OI;
class MigrateFresh extends BaseCommand
{
use HasTenantOptions, DealsWithMigrations, ParallelCommand;
use HasTenantOptions, DealsWithMigrations, ParallelCommand, ConfirmableTrait;
protected $description = 'Drop all tables and re-run all migrations for tenant(s)';
@ -27,6 +28,7 @@ class MigrateFresh extends BaseCommand
$this->addOption('drop-views', null, InputOption::VALUE_NONE, 'Drop views along with tenant tables.', null);
$this->addOption('step', null, InputOption::VALUE_NONE, 'Force the migrations to be run so they can be rolled back individually.');
$this->addOption('force', null, InputOption::VALUE_NONE, 'Force the command to run when in production.', null);
$this->addProcessesOption();
$this->setName('tenants:migrate-fresh');
@ -34,6 +36,10 @@ class MigrateFresh extends BaseCommand
public function handle(): int
{
if (! $this->confirmToProceed()) {
return 1;
}
$success = true;
if ($this->getProcesses() > 1) {

View file

@ -5,8 +5,8 @@ declare(strict_types=1);
namespace Stancl\Tenancy\Features;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Vite;
use Stancl\Tenancy\Contracts\Feature;
use Stancl\Tenancy\Overrides\Vite;
use Stancl\Tenancy\Tenancy;
class ViteBundler implements Feature
@ -21,6 +21,8 @@ class ViteBundler implements Feature
public function bootstrap(Tenancy $tenancy): void
{
$this->app->singleton(\Illuminate\Foundation\Vite::class, Vite::class);
Vite::createAssetPathsUsing(function ($path, $secure = null) {
return global_asset($path);
});
}
}

View file

@ -1,22 +0,0 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Overrides;
use Illuminate\Foundation\Vite as BaseVite;
class Vite extends BaseVite
{
/**
* Generate an asset path for the application.
*
* @param string $path
* @param bool|null $secure
* @return string
*/
protected function assetPath($path, $secure = null)
{
return global_asset($path);
}
}