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: 1113cd0160d9
i18n_source_hash: a68264552836
i18n_provenance: machine
i18n_output_hash: f5d73e5b3f07
i18n_hash_version: 2
---
# データベース {#database}
@@ -145,6 +146,17 @@ SnapOtter はデータの永続化に PostgreSQL 17 と [Drizzle ORM](https://or
| `details` | jsonb | アクション固有のデータ |
| `createdAt` | timestamp | アクション日時 |
### user_preferences {#user-preferences}
ユーザーごとの UI 状態を、設定名をキーとして保持します。ホームページのピン留めしたツールは `PUT /api/v1/preferences` 経由でここに書き込まれます。
| カラム | 型 | 備考 |
|---|---|---|
| `userId` | text | users への FK、削除時にカスケード。`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} のバックアップと復元
リレーショナルデータベースは、アプリの `/data` ボリュームではなく、Postgres コンテナの `SnapOtter-pgdata` ボリュームに存在します。
リレーショナル データベースは、アプリの `/data` ボリュームではなく、Postgres コンテナ`SnapOtter-pgdata` ボリュームに存在します。
**オプション 1: pg_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 状態は含まれません。 [セキュリティと強化](/ja/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 データ ディレクトリをコピーしないでください。ボリューム名はプロジェクトごとにプレフィックスを作成するため、リテラル ラベル `SnapOtter-pgdata` を想定するのではなく、`docker inspect` またはストレージ プラットフォームからマウントされたボリューム ID を解決します。
### 1.xSQLite)からの移行 {#migrating-from-1-x-sqlite}
SnapOtter 1.x からのアップグレードには専用のガイドがあります。[1.x から 2.0 へのアップグレード](./upgrading) を参照してください。要点としては、既存の `/data` ボリュームを再利用すれば、2.0 が初回起動時に `/data/snapotter.db` を自動検出してインポートします(または `SQLITE_MIGRATE_PATH` を設定して明示的に指定します)。まず `snapotter.db` だけでなく `/data` ボリューム全体をバックアップしてください。1.x は SQLite の WAL モードを使うため、停止したコンテナはデータの大半を、ほぼ空の `snapotter.db` のそばにある `snapotter.db-wal` に残していることがよくあります。