mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
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:
@@ -1,8 +1,9 @@
|
||||
---
|
||||
description: "SnapOtter 的 PostgreSQL 数据库架构、表、迁移和备份流程。"
|
||||
i18n_source_hash: 50d5d4f220cf
|
||||
i18n_provenance: human
|
||||
i18n_output_hash: 3289d2d06514
|
||||
i18n_source_hash: a68264552836
|
||||
i18n_provenance: machine
|
||||
i18n_output_hash: 127adc94ef4c
|
||||
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` 卷中。
|
||||
|
||||
**方案 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 状态。使用[安全与强化](/zh-CN/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.x(SQLite)迁移 {#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`。
|
||||
|
||||
Reference in New Issue
Block a user