fix: avoid schema writes on readonly bills sqlite
This commit is contained in:
parent
6c4dfe5983
commit
bde13f359f
@ -103,7 +103,7 @@ class StoreReportRepository
|
||||
/** @return array<string,array<int,array<string,mixed>>> */
|
||||
private function lifecycles(array $names): array
|
||||
{
|
||||
if (! $this->connection->getSchemaBuilder()->hasTable('store_lifecycles')) {
|
||||
if (! $this->hasTable('store_lifecycles')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@ -133,8 +133,8 @@ class StoreReportRepository
|
||||
private function lifecycleSales(array $names): array
|
||||
{
|
||||
if ($names === []
|
||||
|| ! $this->connection->getSchemaBuilder()->hasTable('store_lifecycles')
|
||||
|| ! $this->connection->getSchemaBuilder()->hasTable('bills')) {
|
||||
|| ! $this->hasTable('store_lifecycles')
|
||||
|| ! $this->hasTable('bills')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@ -168,7 +168,7 @@ class StoreReportRepository
|
||||
/** @return array<string,array{period:float,months:array<string,float>}> */
|
||||
private function fallbackSales(array $names): array
|
||||
{
|
||||
if ($names === [] || ! $this->connection->getSchemaBuilder()->hasTable('bills')) {
|
||||
if ($names === [] || ! $this->hasTable('bills')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@ -195,6 +195,18 @@ class StoreReportRepository
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断 SQLite 表是否存在。使用普通只读查询,避免 Schema Builder
|
||||
* 在只读/WAL 挂载下探测表结构时尝试写入数据库。
|
||||
*/
|
||||
private function hasTable(string $table): bool
|
||||
{
|
||||
return $this->connection->select(
|
||||
"SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ? LIMIT 1",
|
||||
[$table],
|
||||
) !== [];
|
||||
}
|
||||
|
||||
private function date(mixed $value, string $fallback): string
|
||||
{
|
||||
$value = trim((string) ($value ?? ''));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user