Added the catalogue models and seed to support phase 3 of the POC prototype in the Persistence package.

This commit is contained in:
javier committed 2026-09-21 12:11:01 +02:00
1 parent 43dcc03da6
commit b1ceed7790
20 files changed
+2035 -8

No files matched your search

+7 -5
View File
@@ -9,6 +9,7 @@ The [Fluent](https://github.com/hummingbird-project/hummingbird-fluent)-based da
| Migrations | `PrepareDB`, the single registrar declaring every migration, in order |
| Readiness | `Probe`, which reports whether the default database answers a `SELECT 1` within a deadline |
| Accounts | `AccountRepository`, which finds an account by email or creates it, returning a `User` snapshot; `CreateUser` seeds the prototype's demo accounts |
| Trade | `TradeRepository`, which reads and writes `Conversation`, `Offer`, and `Sale` snapshots and enforces who may do what, throwing a `TradeError` otherwise; `Sale` carries the five-step handshake's rules as pure functions |
| Catalogue | `CatalogueRepository`, returning `Shop` and `Listing` snapshots narrowed and ordered by a `ListingFilter`; `SeedCatalogue` fills it with the prototype's demo data |
## Design rules
@@ -16,6 +17,7 @@ The [Fluent](https://github.com/hummingbird-project/hummingbird-fluent)-based da
- **One default database.** `Service` registers the selected backend as the *default* database, so repositories resolve it with a plain `fluent.db()` and stay agnostic of which driver is in use.
- **Migrations are declared once, and append-only.** `PrepareDB` registers every migration in the order it must run; alter the schema by adding a migration, never by editing one that has already run. Registering does not apply them: the in-memory backend is migrated at launch, while a shared PostgreSQL database is migrated out of band (the executable's migrate-and-exit mode), so booting instances never race.
- **Models never cross a concurrency boundary.** FluentKit models are mutable reference types, so they stay internal to the package and repositories return `Sendable` value-type snapshots (e.g. `Listing`) instead.
- **Registration order is not creation order.** `AddTradeColumns` is registered ahead of `SeedCatalogue`, whose models write its columns; Fluent tracks migrations by name, so a database already past the seed still gains them.
- **Prototype shortcuts.** `CatalogueRepository` filters in memory, the catalogue fields (series, issue, publisher) are folded into the listing, and the demo data ships as a migration. All three go once real data arrives.
- **Readiness never throws, and never hangs.** `Probe` runs a schema-independent `SELECT 1`, maps every failure to `false`, and races the query against a deadline (2 seconds by default) — a hanging database yields a prompt "not ready" instead of a stalled endpoint.
- **A single connection for the in-memory store.** The SQLite backend is capped at one connection per event loop, so every query reaches the same in-memory database instead of each pooled connection getting a private one.
@@ -28,14 +30,14 @@ Sources are split by visibility, then by kind, one type per file:
```
Sources/
├── Public/
│ ├── Enumerations/ Driver, TLS
│ ├── Enumerations/ Driver, TLS, TradeError
│ ├── Methods/ Service, PrepareDB, Probe
│ ├── Models/ Shop, Listing, ListingFilter, User
│ ├── Repositories/ CatalogueRepository, AccountRepository
│ ├── Models/ Shop, Listing, ListingFilter, User, Conversation, Offer, Sale
│ ├── Repositories/ CatalogueRepository, AccountRepository, TradeRepository
│ └── Types/ Configuration
└── Internal/
├── Migrations/ CreateShop, CreateListing, SeedCatalogue, CreateUser
├── Models/ ShopRecord, ListingRecord, UserRecord
├── Migrations/ CreateShop, CreateListing, AddTradeColumns, SeedCatalogue, CreateUser, CreateTrade
├── Models/ ShopRecord, ListingRecord, UserRecord, ConversationRecord, MessageRecord, OfferRecord, SaleRecord
└── Seeds/ Seed
Tests/
├── Cases/ the test suites, mirroring the Sources/ layout