Run artifact

workspace/targets/FxRates/blueprint/DATABASE.md

DATABASE: FxRates

FieldValue
Version20261026 V1
DescriptionDeclares the rates store and typed repository operations used by FxRates.
Depends OnARCHITECTURE.md
Providesrates repository operations

Persistence Boundary

BoundaryRule
Raw storage accessOnly the generated persistence/ package reaches the store.
Caller dependencyFeatures use the declared repository operations and DTOs, not the schema.
ImplementationDrydock generates the persistence package and DDL from this declaration.

Access Patterns

FEATURE-RATE-001 — Store or replace a published rate

FieldValue
OwnerDATABASE.md
Accesswrite
Repository operationrates.upsert
Compatibilityunchanged
Matchdate, currency

Input: RateUpsertInput

FieldType
datestr
currencystr
ratestr

Output: RateUpsertOutput

FieldType
datestr
currencystr
ratestr

FEATURE-RATE-002 — List rates for a publication date

FieldValue
OwnerDATABASE.md
Accessread
Repository operationrates.by_date
Kindlist
Matchdate
Ordercurrency asc
Compatibilityunchanged

Input: RatesByDateInput

FieldType
datestr

Output: RatesByDateOutput

FieldType
datestr
currencystr
ratestr

FEATURE-RATE-003 — Find publications on or before a date

FieldValue
OwnerDATABASE.md
Accessread
Repository operationrates.publications_through
Kindlist
Matchdate <= requested_date
Orderdate desc
Compatibilityunchanged

Input: RatesPublicationsThroughInput

FieldType
requested_datestr

Output: RatesPublicationsThroughOutput

FieldType
datestr
currencystr
ratestr

FEATURE-RATE-004 — List a currency's rates within optional date bounds

FieldValue
OwnerDATABASE.md
Accessread
Repository operationrates.history
Kindlist
Matchcurrency, date >= start_date, date <= end_date
Orderdate asc
Compatibilityunchanged

Input: RatesHistoryInput

FieldType
currencystr
start_datestr
end_datestr

Output: RatesHistoryOutput

FieldType
datestr
currencystr
ratestr

FEATURE-RATE-005 — List stored rates

FieldValue
OwnerDATABASE.md
Accessread
Repository operationrates.list
Kindlist
Compatibilityunchanged

Input: RatesListInput

FieldType

Output: RatesListOutput

FieldType
datestr
currencystr
ratestr

Schemas

rates

FieldTypeNotes
idINTEGER PKGenerated row identifier.
dateTEXT NOT NULLECB publication date in YYYY-MM-DD form.
currencyTEXT NOT NULLThree-letter uppercase currency code.
rateTEXT NOT NULLECB-published rate text, preserved exactly.

Migrations

Access PatternRevisionState

Config (.env)

KeyTypeRequiredNotes
DATABASE_URLstrNoDatabase DSN; takes precedence over DATABASE_PATH.
DATABASE_PATHstrNoDatabase file path used when DATABASE_URL is unset.

File Stores

StoreRoot dirNotes

External Services

ServiceWrapperNotes

External Libraries

LibraryOwnershipDistributionConsumer Contract
ECB reference ratesFetch featureECB history ZIPFetch downloads and extracts the archive before passing its CSV through the load workflow.

Programmatic Acceptance

=== AC rates-upsert ===
Intent: The repository stores a rate and replaces the value for the same date and currency.

from persistence.testing import db_session

date = "2099-01-02" currency = "QAA" rate = "1.234" replacement = "1.235"

with db_session() as db: first = db.rates.upsert(date=date, currency=currency, rate=rate) assert first.date == date assert first.currency == currency assert first.rate == rate

second = db.rates.upsert(date=date, currency=currency, rate=replacement) assert second.rate == replacement

stored = db.rates.by_date(date=date) assert len([row for row in stored if row.currency == currency]) == 1 assert next(row for row in stored if row.currency == currency).rate == replacement === END AC rates-upsert ===

=== AC rates-by-date ===
Intent: The repository returns the stored rates for a requested publication date.

from persistence.testing import db_session

date = "2099-02-03" currency = "QAB" rate = "2.50"

with db_session() as db: db.rates.upsert(date=date, currency=currency, rate=rate) rows = db.rates.by_date(date=date) assert any(row.date == date and row.currency == currency and row.rate == rate for row in rows) === END AC rates-by-date ===

=== AC rates-publications-through ===
Intent: The repository returns stored publications on or before the requested date in descending date order.

from persistence.testing import db_session

earlier = "2099-03-01" later = "2099-03-02" requested = later currency = "QAC"

with db_session() as db: db.rates.upsert(date=earlier, currency=currency, rate="3") db.rates.upsert(date=later, currency=currency, rate="4") rows = db.rates.publications_through(requested_date=requested) dates = list(dict.fromkeys(row.date for row in rows)) assert dates == sorted(dates, reverse=True) assert earlier in dates assert later in dates === END AC rates-publications-through ===

=== AC rates-history ===
Intent: The repository returns a currency's rates within inclusive optional date bounds in ascending date order.

from persistence.testing import db_session

currency = "QAD" start = "2099-04-02" end = "2099-04-03" before = "2099-04-01" after = "2099-04-04"

with db_session() as db: db.rates.upsert(date=before, currency=currency, rate="1") db.rates.upsert(date=start, currency=currency, rate="2") db.rates.upsert(date=end, currency=currency, rate="3") db.rates.upsert(date=after, currency=currency, rate="4") rows = db.rates.history(currency=currency, start_date=start, end_date=end) assert [row.date for row in rows] == [start, end] === END AC rates-history ===

=== AC rates-list ===
Intent: The repository lists stored rates with their published text.

from persistence.testing import db_session

date = "2099-05-06" currency = "QAE" rate = "5.006"

with db_session() as db: db.rates.upsert(date=date, currency=currency, rate=rate) rows = db.rates.list() assert any(row.date == date and row.currency == currency and row.rate == rate for row in rows) === END AC rates-list ===

User Acceptance

Guardrails