fix(core): installer_completed fast-path가 빈 DB 배포 시 부팅을 깨뜨리는 문제 수정 및 7.0.3 릴리스
INSTALLER_COMPLETED=true 가 적힌 .env 를 빈 DB 새 서버에 복사한 뒤
php artisan migrate 로 테이블을 만들기 전에 앱이 부팅되면, installer_completed
fast-path 가 테이블 존재를 잘못 전제하여 뒤따르는 쿼리가 table not found 로
부팅을 깨뜨렸다. 마이그레이션을 실행하려는 부팅에서 그 명령이 오히려 실패하는
닭-달걀 상태가 된다.
fast-path 자체(매 요청 information_schema 쿼리 제거 성능 최적화)는 유지하되,
이미 존재하던 참조 구현(LanguagePackServiceProvider::isRegistryReady)의 방어
패턴을 InstallerContext::isSchemaMutatingCommand 로 SSoT 화하여 나머지 5곳에
통일 적용했다.
- app/Support/InstallerContext.php: 마이그레이션 계열 콘솔 명령 판정 헬퍼
(migrate/migrate:fresh/migrate:refresh/migrate:rollback/migrate:reset/db:wipe)
- Caches{Module,Plugin,Template}Status: fast-path 앞에 && 가드
- {Module,Plugin}RouteServiceProvider: hasTable 검증 진입 조건에 || 가드로
무방비 pluck 도달 차단
- LanguagePackServiceProvider: 인라인 argv 검사를 헬퍼로 치환(migrate:refresh 보강)
부류 B(NotificationHookListener, IdentityPolicyRepository)는 fast-path 이후
쿼리가 이미 try/catch 로 보호되어 빈 DB 에서도 안전하므로 수정 제외.
최초 설치 흐름은 migrate 시점에 완료 플래그가 없어(false) 이번 가드의 영향권
밖이며 원래대로 hasTable 폴백을 탄다. 가드가 실제 발동하는 유일 케이스는
"플래그 true + 빈 DB" 뿐이고, 정상 운영 웹 요청은 fast-path 성능이 유지된다.
회귀 테스트: InstallerContextTest 8건 + InstallerCompletedGuardTest 5건 추가
(수정 전 5건 fail → 수정 후 green). 관련 스위트 355 passed.
7.0.3 출시 버전 bump: 코어 버전 SSoT 7곳 + CHANGELOG 동기화.
This commit is contained in:
1 parent
13aeb433cc
commit
c26b49a997
16 files changed
+386
-23
No files matched your search
@@ -6,6 +6,7 @@ use App\Contracts\Extension\CacheInterface;
|
||||
use App\Enums\ExtensionStatus;
|
||||
use App\Extension\Cache\CoreCacheDriver;
|
||||
use App\Models\Module;
|
||||
use App\Support\InstallerContext;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
@@ -63,8 +64,6 @@ trait CachesModuleStatus
|
||||
/**
|
||||
* 모듈 상태 캐시를 무효화합니다.
|
||||
* 모듈 상태 변경 시 (install, activate, deactivate, uninstall) 호출해야 합니다.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function invalidateModuleStatusCache(): void
|
||||
{
|
||||
@@ -79,10 +78,14 @@ trait CachesModuleStatus
|
||||
* 설치 완료 상태(`config('app.installer_completed')`)일 때는 테이블 존재를
|
||||
* 전제로 하여 `Schema::hasTable()` 호출을 건너뜁니다. 인스톨러 이전 환경이나
|
||||
* 테스트에서는 기존 체크 경로로 폴백합니다.
|
||||
*
|
||||
* 단, 마이그레이션 계열 명령 실행 중에는 `INSTALLER_COMPLETED=true` 라도 테이블이
|
||||
* 아직 없을 수 있으므로(빈 DB 새 서버에 .env 복사 후 migrate 전) fast-path 를
|
||||
* 신뢰하지 않고 실제 `Schema::hasTable()` 폴백으로 진입합니다.
|
||||
*/
|
||||
private static function isExtensionTableReady(string $table): bool
|
||||
{
|
||||
if (config('app.installer_completed')) {
|
||||
if (! InstallerContext::isSchemaMutatingCommand() && config('app.installer_completed')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Contracts\Extension\CacheInterface;
|
||||
use App\Enums\ExtensionStatus;
|
||||
use App\Extension\Cache\CoreCacheDriver;
|
||||
use App\Models\Plugin;
|
||||
use App\Support\InstallerContext;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
@@ -63,8 +64,6 @@ trait CachesPluginStatus
|
||||
/**
|
||||
* 플러그인 상태 캐시를 무효화합니다.
|
||||
* 플러그인 상태 변경 시 (install, activate, deactivate, uninstall) 호출해야 합니다.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function invalidatePluginStatusCache(): void
|
||||
{
|
||||
@@ -76,10 +75,14 @@ trait CachesPluginStatus
|
||||
/**
|
||||
* 설치 완료 상태에서는 `Schema::hasTable()` 호출을 건너뜁니다.
|
||||
* 인스톨러 이전 환경이나 테스트에서는 기존 체크 경로로 폴백합니다.
|
||||
*
|
||||
* 단, 마이그레이션 계열 명령 실행 중에는 `INSTALLER_COMPLETED=true` 라도 테이블이
|
||||
* 아직 없을 수 있으므로(빈 DB 새 서버에 .env 복사 후 migrate 전) fast-path 를
|
||||
* 신뢰하지 않고 실제 `Schema::hasTable()` 폴백으로 진입합니다.
|
||||
*/
|
||||
private static function isPluginTableReady(): bool
|
||||
{
|
||||
if (config('app.installer_completed')) {
|
||||
if (! InstallerContext::isSchemaMutatingCommand() && config('app.installer_completed')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Contracts\Extension\CacheInterface;
|
||||
use App\Enums\ExtensionStatus;
|
||||
use App\Extension\Cache\CoreCacheDriver;
|
||||
use App\Models\Template;
|
||||
use App\Support\InstallerContext;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
@@ -86,8 +87,6 @@ trait CachesTemplateStatus
|
||||
/**
|
||||
* 템플릿 상태 캐시를 무효화합니다.
|
||||
* 템플릿 상태 변경 시 (install, activate, deactivate, uninstall) 호출해야 합니다.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function invalidateTemplateStatusCache(): void
|
||||
{
|
||||
@@ -101,10 +100,14 @@ trait CachesTemplateStatus
|
||||
/**
|
||||
* 설치 완료 상태에서는 `Schema::hasTable()` 호출을 건너뜁니다.
|
||||
* 인스톨러 이전 환경이나 테스트에서는 기존 체크 경로로 폴백합니다.
|
||||
*
|
||||
* 단, 마이그레이션 계열 명령 실행 중에는 `INSTALLER_COMPLETED=true` 라도 테이블이
|
||||
* 아직 없을 수 있으므로(빈 DB 새 서버에 .env 복사 후 migrate 전) fast-path 를
|
||||
* 신뢰하지 않고 실제 `Schema::hasTable()` 폴백으로 진입합니다.
|
||||
*/
|
||||
private static function isTemplateTableReady(): bool
|
||||
{
|
||||
if (config('app.installer_completed')) {
|
||||
if (! InstallerContext::isSchemaMutatingCommand() && config('app.installer_completed')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ use App\Services\LanguagePack\LanguagePackBundledRegistrar;
|
||||
use App\Services\LanguagePack\LanguagePackRegistry;
|
||||
use App\Services\LanguagePack\LanguagePackSeedInjector;
|
||||
use App\Services\LanguagePack\LanguagePackTranslator;
|
||||
use App\Support\InstallerContext;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\File;
|
||||
@@ -477,8 +478,7 @@ class LanguagePackServiceProvider extends ServiceProvider
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->app->runningInConsole()
|
||||
&& in_array($_SERVER['argv'][1] ?? null, ['migrate', 'migrate:fresh', 'migrate:rollback', 'migrate:reset', 'db:wipe'], true)) {
|
||||
if (InstallerContext::isSchemaMutatingCommand()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Enums\ExtensionStatus;
|
||||
use App\Extension\ExtensionManager;
|
||||
use App\Extension\Testing\ExtensionTestAllowlist;
|
||||
use App\Models\Module;
|
||||
use App\Support\InstallerContext;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
@@ -52,7 +53,12 @@ class ModuleRouteServiceProvider extends ServiceProvider
|
||||
|
||||
// 설치 완료 상태에서는 Schema introspection 을 건너뜀 (매 요청 쿼리 제거).
|
||||
// 인스톨러 이전 환경에서는 기존 체크 경로로 폴백.
|
||||
if (! config('app.installer_completed')) {
|
||||
//
|
||||
// 단, 마이그레이션 계열 명령 실행 중에는 INSTALLER_COMPLETED=true 라도 테이블이
|
||||
// 아직 없을 수 있으므로(빈 DB 새 서버에 .env 복사 후 migrate 전) fast-path 를
|
||||
// 무력화하고 hasTable 검증 경로로 진입한다. 빈 DB 면 여기서 early return 하여
|
||||
// 아래 무방비 pluck 이 table not found 로 부팅을 깨뜨리는 것을 막는다.
|
||||
if (! config('app.installer_completed') || InstallerContext::isSchemaMutatingCommand()) {
|
||||
try {
|
||||
if (! Schema::hasTable('modules')) {
|
||||
return;
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Providers;
|
||||
|
||||
use App\Extension\ExtensionManager;
|
||||
use App\Extension\Testing\ExtensionTestAllowlist;
|
||||
use App\Support\InstallerContext;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
@@ -48,7 +49,12 @@ class PluginRouteServiceProvider extends ServiceProvider
|
||||
|
||||
// 설치 완료 상태에서는 Schema introspection 을 건너뜀 (매 요청 쿼리 제거).
|
||||
// 인스톨러 이전 환경에서는 기존 체크 경로로 폴백.
|
||||
if (! config('app.installer_completed')) {
|
||||
//
|
||||
// 단, 마이그레이션 계열 명령 실행 중에는 INSTALLER_COMPLETED=true 라도 테이블이
|
||||
// 아직 없을 수 있으므로(빈 DB 새 서버에 .env 복사 후 migrate 전) fast-path 를
|
||||
// 무력화하고 hasTable 검증 경로로 진입한다. 빈 DB 면 여기서 early return 하여
|
||||
// 이후 플러그인 부팅/상태 조회가 table not found 로 부팅을 깨뜨리는 것을 막는다.
|
||||
if (! config('app.installer_completed') || InstallerContext::isSchemaMutatingCommand()) {
|
||||
try {
|
||||
if (! Schema::hasTable('plugins')) {
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
/**
|
||||
* 부팅 시점 "DB 스키마 준비성" 판정에 쓰이는 인스톨러 컨텍스트 헬퍼.
|
||||
*
|
||||
* `config('app.installer_completed')` fast-path 는 프로덕션에서 `Schema::hasTable()`
|
||||
* 호출을 건너뛰어 매 요청 오버헤드를 제거한다. 그러나 `INSTALLER_COMPLETED=true` 가
|
||||
* 기록된 `.env` 를 빈 DB 새 서버에 복사한 뒤 `php artisan migrate` 로 테이블을
|
||||
* 만들기 전에 앱이 부팅되면, fast-path 가 테이블 존재를 잘못 전제하여 뒤따르는
|
||||
* 쿼리가 "table not found" 로 부팅을 깨뜨린다.
|
||||
*
|
||||
* 이 헬퍼는 스키마를 파괴/재생성하는 마이그레이션 계열 콘솔 명령 판정을 단일
|
||||
* SSoT 로 캡슐화하여, 해당 컨텍스트에서 fast-path 를 무력화하는 가드에 쓰인다.
|
||||
*/
|
||||
class InstallerContext
|
||||
{
|
||||
/**
|
||||
* 스키마를 파괴/재생성하는 콘솔 명령(마이그레이션 계열)이 실행 중인지 판정합니다.
|
||||
*
|
||||
* 이 컨텍스트에서는 `installer_completed=true` 라도 테이블이 아직 없을 수 있으므로
|
||||
* fast-path(hasTable 스킵)를 신뢰해서는 안 됩니다. 웹 요청 등 콘솔이 아닌
|
||||
* 실행 경로에서는 항상 false 를 반환합니다.
|
||||
*
|
||||
* @return bool 마이그레이션 계열 명령 실행 중 여부
|
||||
*/
|
||||
public static function isSchemaMutatingCommand(): bool
|
||||
{
|
||||
if (! app()->runningInConsole()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return in_array(
|
||||
$_SERVER['argv'][1] ?? null,
|
||||
['migrate', 'migrate:fresh', 'migrate:refresh', 'migrate:rollback', 'migrate:reset', 'db:wipe'],
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user