fix: release QA hardening across processing, media, security, and CI gates (#649)

A release-readiness QA pass over the whole product. The commits split into
defects a user would hit and gates that were reporting green while measuring
nothing.

## Fixes that change behaviour

Rate limiting was bypassable on every install: TRUST_PROXY defaulted to true, so
request.ip came from a client-set header and a forged X-Forwarded-For got past
the login limiter. The default is now a private-network trust list.

A transient Postgres outage stranded in-flight jobs, leaving finished output on
disk with no row pointing at it. A reconciler now resolves those rows and adopts
the bytes rather than dropping the work.

A Redis connection that moved to a new address wedged every read-blocked
consumer, so completions stopped signalling while health still answered 200.
Socket timeouts plus subscriber pings recover it.

Installing more than one AI bundle left the shared venv multi-versioned and
silently broke three tools. The installer now reconciles distributions to one
version each.

Converting an image to JXL at quality 1 through 4 returned a 500, because
libjxl 0.7 rejects the distance those values compute. The quality is floored at
what the encoder honours. A missing ffmpeg was also reported to the user as a
corrupt upload; it now says the engine is unavailable.

RAW uploads reached an unpatched LibRaw on arm64, so it is built from source at
0.22.2, and the release scan was split so it can fail on an unfixed critical
instead of hiding it behind ignore-unfixed.

## Gates that could not fail

Two mutation lanes ran zero mutants because Stryker crawled the gitignored docs
build; coverage discarded its whole report on any failing test; the lint gate
skipped root tests, scripts, and two workspaces; and several generated matrices
counted a host missing ffmpeg as a passing tool. Each now measures what it
claims.

Full evidence and the outstanding release items are tracked locally and are not
part of this branch.
This commit is contained in:
SnapOtter
2026-07-27 15:37:30 +08:00
committed by GitHub
parent bc32f86a07
commit d10d0f544f
855 changed files with 54564 additions and 13092 deletions
+35 -15
View File
@@ -1,8 +1,9 @@
---
description: "SnapOtter 的 PostgreSQL 資料庫結構、資料表、遷移,以及備份程序。"
i18n_source_hash: 50d5d4f220cf
i18n_provenance: human
i18n_output_hash: 34debcc24c5a
i18n_source_hash: a68264552836
i18n_provenance: machine
i18n_output_hash: 867212c1ca88
i18n_hash_version: 2
---
# 資料庫 {#database}
@@ -145,6 +146,17 @@ SnapOtter 使用 PostgreSQL 17 搭配 [Drizzle ORM](https://orm.drizzle.team/)
| `details` | jsonb | 動作特定的資料 |
| `createdAt` | timestamp | 動作時間 |
### user_preferences {#user-preferences}
依偏好設定名稱存放的個別使用者介面狀態。首頁的已釘選工具透過 `PUT /api/v1/preferences` 寫入此處。
| 欄位 | 型別 | 說明 |
|---|---|---|
| `userId` | text | 指向 users 的外鍵,連帶刪除。與 `key` 共同構成主鍵 |
| `key` | text | 偏好設定名稱。與 `userId` 共同構成主鍵 |
| `value` | jsonb | 偏好設定內容 |
| `updatedAt` | timestamp | 最後寫入時間 |
## 遷移 {#migrations}
Drizzle 處理結構遷移。遷移檔案位於 `apps/api/drizzle/`。在開發期間:
@@ -157,29 +169,37 @@ npx drizzle-kit migrate # apply pending migrations
在生產環境中,待處理的遷移會在啟動時自動套用。
## 備份與還原 {#backup-and-restore}
## 備份與還原{#backup-and-restore}
關聯式資料庫位於 Postgres 容器的 `SnapOtter-pgdata` 磁碟區,而非應用程式的 `/data` 磁碟區
關聯式資料庫位於 Postgres 容器的 `SnapOtter-pgdata` 卷中,而不是應用程式的 `/data` 卷中
**選項 1pg_dump(建議)**
**帶有驗證的邏輯備份(建議)**
```bash
# Dump the database while the stack is running
docker exec SnapOtter-postgres pg_dump -U snapotter snapotter > backup.sql
# Dump into PostgreSQL's portable custom archive format
docker exec SnapOtter-postgres \
pg_dump --format=custom --no-owner -U snapotter snapotter > snapotter.dump
test -s snapotter.dump
docker exec -i SnapOtter-postgres pg_restore --list < snapotter.dump >/dev/null
# Restore into a fresh database
cat backup.sql | docker exec -i SnapOtter-postgres psql -U snapotter snapotter
# Restore into a fresh/disposable target first and fail on the first SQL error
docker exec -i SnapOtter-postgres \
pg_restore --exit-on-error --clean --if-exists --no-owner \
-U snapotter -d snapotter < snapotter.dump
```
**選項 2:磁碟區快照**
此資料庫轉儲不包含以 `/data/files` 保存的庫物件或 Redis 中持久的 BullMQ 狀態。使用[安全性與強化](/zh-TW/guide/security#backup-and-recovery) 中的協調程序備份和還原這些內容。
**冷捲快照**
```bash
# Stop the stack, then snapshot the pgdata volume
docker compose down
docker run --rm -v SnapOtter-pgdata:/data -v $(pwd)/backup:/backup \
alpine tar czf /backup/snapotter-pgdata.tar.gz -C /data .
# Stop every service first, then use your storage platform to snapshot the
# PostgreSQL, app-data, and Redis volumes as one crash-consistent set.
docker compose -f docker/docker-compose.yml stop
```
不要使用 `tar` 複製即時 PostgreSQL 資料目錄。按項目編寫磁碟區名稱前綴,因此從 `docker inspect` 或您的儲存平台解析已安裝的磁碟區 ID,而不是假設文字標籤 `SnapOtter-pgdata`
### 從 1.xSQLite)遷移 {#migrating-from-1-x-sqlite}
從 SnapOtter 1.x 升級有其專屬指南:見[從 1.x 升級到 2.0](./upgrading)。簡而言之,重複使用你既有的 `/data` 磁碟區,2.0 會在首次開機時自動偵測並匯入 `/data/snapotter.db`(或設定 `SQLITE_MIGRATE_PATH` 明確指向它)。請先備份整個 `/data` 磁碟區,而不只是 `snapotter.db`1.x 使用 SQLite 的 WAL 模式,所以一個已停止的容器往往會把它大部分的資料留在 `snapotter.db-wal` 中,旁邊只有一個幾乎空白的 `snapotter.db`