Commit 1202a9b
authored
feat: Update current-account persistence layer for dimension-agnostic Amount (#1251)
* feat: Add precision column migrations for account, lien, withdrawal tables
Add precision column to account table (default 2 for existing CURRENCY
accounts) and instrument_code/dimension/precision columns to lien and
withdrawal tables. Follows CockroachDB rules: separate migrations for
DDL and DML.
* feat: Update persistence entities and repositories for dimension-agnostic Amount
Add Precision field to CurrentAccountEntity, instrument_code/dimension/precision
fields to LienEntity and WithdrawalEntity. Update toDomain/toEntity functions
to use entity.Precision instead of hardcoded 0, enabling correct Amount
reconstruction for non-CURRENCY instruments (ENERGY, CARBON, COMPUTE).
Legacy currency column preserved for backward compatibility; instrument_code
is the canonical source with fallback to currency for pre-migration rows.
* test: Update test table schemas for precision columns; add multi-asset round-trip tests
Update inline table creation SQL in all persistence test helpers to include
precision, instrument_code, and dimension columns. Add multi_asset_repository_test.go
with round-trip tests for ENERGY (KWH/precision=3), CARBON (CARBON_CREDIT/precision=4),
COMPUTE (GPU_HOUR/precision=6) accounts, liens, and withdrawals. Includes backward
compatibility test for legacy currency column fallback.
* fix: Add check constraints and correct backfill logic for precision migrations
Address CodeRabbit feedback:
- Add CHECK constraints to prevent negative precision on account, lien, withdrawal
- Fix backfill to handle JPY exception (precision=0) using CASE expression
- Fix lien/withdrawal backfill to JOIN account for authoritative dimension/precision
values instead of hardcoding CURRENCY/2
* fix: Use instrument_code for lien consistency check instead of legacy currency column
COUNT(DISTINCT currency) returns 2 for a mix of CURRENCY and non-CURRENCY liens
because non-CURRENCY liens store empty string in currency. Use instrument_code
instead for accurate multi-asset consistency validation.
* fix: Add instrument_code non-empty constraints after backfill
The instrument_code non-empty check constraints must be in migration 004
(after the backfill) rather than 003, because existing rows have the
default empty string until backfilled. Adding these constraints before
the backfill would reject existing rows.
Addresses CodeRabbit feedback on missing integrity constraints.
* fix: Update schema validation test entities to include instrument_code
The new chk_lien_instrument_code_non_empty and
chk_withdrawal_instrument_code_non_empty constraints require instrument_code
to be non-empty. Update testLienEntity and testWithdrawalEntity to populate
InstrumentCode, Dimension, and Precision fields on all created test rows.
* fix: Add precision/instrument_code columns to service-layer test DDL
Four service integration tests use manual DDL to create test schemas.
Add precision INT NOT NULL DEFAULT 2 to all account table definitions,
and add instrument_code/dimension/precision columns to lien table
definitions, matching the schema added in migration 20260226000003.
* chore: Upgrade golang.org/x/net to v0.51.0 (GO-2026-4559)
Fixes vulnerability GO-2026-4559: sending certain HTTP/2 frames can
cause a server to panic in golang.org/x/net. Upgrade from v0.50.0
to v0.51.0 which contains the fix.
---------
Co-authored-by: Ben Coombs <bjcoombs@users.noreply.github.com>1 parent 472263c commit 1202a9b
21 files changed
Lines changed: 523 additions & 83 deletions
File tree
- services/current-account
- adapters/persistence
- migrations
- service
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
57 | | - | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
| 132 | + | |
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
175 | | - | |
| 175 | + | |
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | | - | |
| 182 | + | |
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1402 | 1402 | | |
1403 | 1403 | | |
1404 | 1404 | | |
1405 | | - | |
1406 | | - | |
| 1405 | + | |
| 1406 | + | |
1407 | 1407 | | |
1408 | 1408 | | |
1409 | 1409 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
28 | 31 | | |
29 | 32 | | |
30 | 33 | | |
| |||
Lines changed: 26 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
251 | 252 | | |
252 | 253 | | |
253 | 254 | | |
254 | | - | |
| 255 | + | |
| 256 | + | |
255 | 257 | | |
256 | 258 | | |
257 | 259 | | |
258 | | - | |
| 260 | + | |
259 | 261 | | |
260 | 262 | | |
261 | 263 | | |
| |||
293 | 295 | | |
294 | 296 | | |
295 | 297 | | |
296 | | - | |
| 298 | + | |
| 299 | + | |
297 | 300 | | |
298 | 301 | | |
299 | 302 | | |
300 | | - | |
| 303 | + | |
301 | 304 | | |
302 | 305 | | |
303 | 306 | | |
| |||
328 | 331 | | |
329 | 332 | | |
330 | 333 | | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
331 | 341 | | |
332 | 342 | | |
333 | 343 | | |
334 | 344 | | |
335 | | - | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
336 | 349 | | |
337 | 350 | | |
338 | 351 | | |
| |||
363 | 376 | | |
364 | 377 | | |
365 | 378 | | |
366 | | - | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
367 | 387 | | |
368 | 388 | | |
369 | 389 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
41 | 44 | | |
42 | 45 | | |
43 | 46 | | |
| |||
662 | 665 | | |
663 | 666 | | |
664 | 667 | | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
665 | 671 | | |
666 | 672 | | |
667 | 673 | | |
| |||
0 commit comments