Schema hardening roadmap#
The current schema is correct for the v1 workflow but relies on Python for guarantees that a production database should also enforce. These changes are required before the system is relied on for real positions, and should be delivered as Alembic migrations.
Until Alembic exists, schema changes are not applied to existing database files: delete the old
db/*.dbfiles and runscripts/init_db.pyagain.
# |
Change |
Reason |
|---|---|---|
1 |
|
Exact decimal arithmetic and explicit rounding; floats cannot represent most decimal prices exactly. |
2 |
Remaining |
Invariants hold even if a writer bypasses the service layer. |
3 |
Unique |
Makes the idempotent-replace guarantee a database fact; prevents duplicate or ambiguous limits. |
4 |
Foreign key |
Within one database, foreign keys are enforceable and should be. |
5 |
Timezone-aware UTC timestamps ( |
Naive timestamps are ambiguous across hosts and daylight-saving changes. |
6 |
|
Avoid 32-bit exhaustion at scale. |
7 |
Append-only trade events: amendments and cancels as new rows linked to the original trade, with |
Full audit trail of who changed what and when; no destructive updates. |
8 |
|
Detects the partial-failure case across databases, makes reruns visible, and lets any past figure be reproduced. |
9 |
Price corrections as new versions ( |
Vendor corrections must be traceable, and real data must be able to supersede simulated data; fewer indexes on a write-heavy table. |
10 |
Composite trade-replay index |
Serves the exact ordering the P&L replay uses. |
11 |
Effective-dating for instrument attributes that can change ( |
Historical calculations must use the attributes valid at that time. |
12 |
Alembic baseline of the current schema, then all changes above as migrations |
Repeatable, reviewable, reversible schema change; replaces |
13 |
Propagate |
A P&L figure derived from simulated prices must not be readable as real. |
14 |
The multi-asset tables listed in Multi-asset design: |
Added when the first instrument of each class is introduced, not before. |
15 |
Price basis: |
A mark or return series with an unstated basis can be off by half the spread, and mixing bases corrupts VaR. Bid, ask and mid serve different purposes (execution, liquidation value, reference valuation). |