feat(storage): store mongo values as native BSON documents

Implement mongodb_value_codec to encode portfolio/gold/stock values as native
BSON documents instead of JSON-serialized byte strings. Reduces storage size,
improves query efficiency, and eliminates unmarshal overhead. Native BSON
encoding preserves int64 fidelity and enables future native-format queries.
Add NativeValueRepresentation and Int64Fidelity tests validating lossless
encoding. Update migration tool comments. Document native-value behavior
in deploy guide. Update phase-01 plan with implementation notes.
This commit is contained in:
2026-06-28 12:52:48 +07:00
parent 6bc5f334bb
commit e8a6dbb4de
5 changed files with 137 additions and 10 deletions
+8
View File
@@ -63,6 +63,14 @@ and the `STOCK/COIN/GOLD *_API_URL` overrides (modules use coded defaults).
4. Copy the `mongodb+srv://…` connection string into `MONGO_URL` and put the
db name in `MONGO_DATABASE`.
> Storage layout: one collection per module; each document is
> `{ _id: <user key>, value: <native BSON document>, version, updatedAt }`.
> Values are stored as native BSON (objects/arrays expand and are queryable in
> Compass); non-JSON values (e.g. a date guard) are plain strings. Concurrency
> uses the `version` field (optimistic lock). If you migrated data with an older
> build that stored `value` as a string/blob, re-run the migrator (idempotent)
> so values become native.
## 2. Coolify
1. New resource → from this Git repo (Docker Compose), or a prebuilt image.