feat(storage): Compose-Profil postgres, CI-Matrix mongo/postgres, API-Smoke-Test, Doku
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
23d9b83567
commit
bbfebc0095
5 files changed
+224
-1
No files matched your search
@@ -0,0 +1,66 @@
|
||||
# Storage: MongoDB oder PostgreSQL pro Instanz
|
||||
|
||||
Umsetzung von [ADR 0002](../adr/0002-storage-mongo-postgres.md) (Gitea #7). Pro Instanz ist **genau ein**
|
||||
Backend aktiv. Einen Datenumzug zwischen den Backends gibt es nicht (einzelne Brews: Download/Import).
|
||||
|
||||
## Konfiguration
|
||||
|
||||
| Variable | Bedeutung |
|
||||
| --- | --- |
|
||||
| `HB_DB_DRIVER` | `mongo` (Standard) oder `postgres` |
|
||||
| `MONGODB_URI` | wie Upstream (nur bei `mongo`) |
|
||||
| `HB_POSTGRES_URL` | z. B. `postgres://hb:…@postgres:5432/homebrewery` (Pflicht bei `postgres`) |
|
||||
| `HB_POSTGRES_POOL_MAX` | Pool-Größe, Standard `10` |
|
||||
|
||||
Beim Start wird nur das gewählte Backend verbunden (bei `postgres` verbindet sich Mongoose nicht). Fehlt
|
||||
`HB_POSTGRES_URL` oder ist der Server älter als PostgreSQL 18 (`server_version_num` < 180000), bricht der Start mit
|
||||
klarer Meldung ab. Die Migrationen (`server/storage/postgres/migrations/`) laufen beim Start automatisch
|
||||
(Kysely-Migrator mit Lock-Tabelle, bei Fehler Abbruch).
|
||||
|
||||
## Compose
|
||||
|
||||
```bash
|
||||
# Standard (Mongo, wie bisher)
|
||||
docker compose up --build
|
||||
|
||||
# PostgreSQL 18, ganz ohne Mongo: Profil `postgres`, Service `homebrewery-pg`
|
||||
docker compose --profile postgres up --build homebrewery-pg
|
||||
```
|
||||
|
||||
Die Service-Namen gehören dazu: Mit `--profile postgres up` ohne Namen startet Compose zusätzlich die
|
||||
profillosen Services `homebrewery` und `mongodb` (beide auf `APP_PORT`).
|
||||
|
||||
## Repository-Schicht
|
||||
|
||||
`server/storage/` – `getStorage()` liefert `{ brews, notifications, users }` (`gitConnections`, `brewGitLinks`,
|
||||
`brewAssets` kommen mit M3/M4). Alle Methoden sind `async` und liefern plain objects mit `id`, `text` immer
|
||||
entpackt, nie `textBin`. Nicht gefunden: `findBy…` liefert `null`.
|
||||
|
||||
Abweichungen von ADR 0002 (Details beim Umsetzen ergeben):
|
||||
|
||||
- `searchPublished(params)` liefert `{ brews, total }`; `total` nur mit `withTotal: true`, Brews nicht mit
|
||||
`limit: 0` (für `/api/vault/total`).
|
||||
- Sperren: `setLock(shareId, lock, { overwrite })`, `removeLock`, `requestReview`, `removeReviewRequest` liefern
|
||||
`{ result, brew }` (`'locked' | 'not-found' | 'already-locked'` usw.), damit die Fehlercodes der Admin-API
|
||||
unverändert bleiben und die Prüfung atomar ist (PG: eine Transaktion mit `FOR UPDATE`).
|
||||
- Notifications: `list()`, `create(data)`, `deleteByDismissKey(key)`; das Feld heißt jetzt `id` statt `_id`.
|
||||
- `/admin/clean/script/:id` läuft über Repository und `updateBrew` und funktioniert damit auch unter PG
|
||||
(ADR: 501). Nur `cleanupJunk`, `cleanupLost`, `finduncompressed` und `compress` antworten unter PG mit `501`.
|
||||
- Die Upstream-Modelle (`homebrew.model.js`, `notifications.model.js`, `db.js`) sind unverändert.
|
||||
|
||||
## Tests
|
||||
|
||||
```bash
|
||||
# Postgres (frisches Schema test_<random> je Suite, wird danach gelöscht)
|
||||
HB_TEST_POSTGRES_URL=postgres://postgres:pw@127.0.0.1:5432/postgres npm run test:storage
|
||||
# Mongo (frische DB test_<random>)
|
||||
HB_TEST_MONGODB_URI=mongodb://127.0.0.1:27017 npm run test:storage
|
||||
```
|
||||
|
||||
Ohne die Variablen überspringen sich die Specs mit Warnung. `npm test` läuft weiter ohne Datenbank.
|
||||
Beide Variablen gleichzeitig sind erlaubt. Die CI (`storage`-Job, Matrix `mongo`/`postgres`) setzt je eine.
|
||||
|
||||
Hinweise zu Mongo unter Jest: Der Mongo-Treiber braucht dort `runtimeAdapters: { os }` (sonst sendet er keine
|
||||
Client-Metadaten und der Server lehnt den Handshake ab; die Specs setzen das). `Model.init()`/`syncIndexes()` auf
|
||||
`Homebrew` scheitert auf aktuellen Servern am Upstream-Index `{ lock: 1, sparse: true }`; die Specs legen die
|
||||
nötigen Indizes selbst an. MongoDB ≥ 5 braucht eine CPU mit AVX; auf Hosts ohne AVX hilft lokal `mongo:4.4`.
|
||||
Reference in new issue
Block a user