39 lines
1.1 KiB
PHP
39 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Utilities\SystemDatabaseConfiguration;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
use RuntimeException;
|
|
use Throwable;
|
|
|
|
class VerifySystemDatabase extends Command
|
|
{
|
|
protected $signature = 'system-database:verify';
|
|
|
|
protected $description = '在新的 Laravel 进程中验证当前共享系统数据库';
|
|
|
|
public function handle(SystemDatabaseConfiguration $configuration): int
|
|
{
|
|
try {
|
|
$settings = $configuration->current();
|
|
|
|
if ($settings['mode'] !== 'shared') {
|
|
throw new RuntimeException('当前不是共享系统数据库模式。');
|
|
}
|
|
|
|
DB::purge((string) $settings['connection']);
|
|
DB::reconnect((string) $settings['connection']);
|
|
DB::selectOne('SELECT 1');
|
|
$configuration->probe($settings);
|
|
} catch (Throwable) {
|
|
return self::FAILURE;
|
|
}
|
|
|
|
$this->components->info('共享系统数据库已通过应用级验证。');
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|