fix: system_configs autoload 在 DB 不可用时不阻断启动

This commit is contained in:
萝卜
2026-03-15 20:08:46 +08:00
parent 452ac450c8
commit 3484402ea8

View File

@@ -26,7 +26,13 @@ class AppServiceProvider extends ServiceProvider
// 安全阀: // 安全阀:
// - 在测试/首次安装阶段,可能尚未执行迁移;此时 system_configs 表不存在,必须跳过。 // - 在测试/首次安装阶段,可能尚未执行迁移;此时 system_configs 表不存在,必须跳过。
// - 任意配置项解析失败(如 JSON 格式错误)也不应阻断应用启动。 // - 任意配置项解析失败(如 JSON 格式错误)也不应阻断应用启动。
if (! Schema::hasTable('system_configs')) { // 若数据库连接不可用(例如本地 mysql 未启动 / CI 环境Schema::hasTable() 会直接抛异常。
// 这里加一层 try/catch确保“治理配置加载”不会阻断应用启动。
try {
if (! Schema::hasTable('system_configs')) {
return;
}
} catch (\Throwable $e) {
return; return;
} }