Skip to content

Mirror transactions into a structured D1 store - #33

Open
tdtgit wants to merge 1 commit into
mainfrom
claude/nice-mayer-4qkbcl
Open

tdtgit wants to merge 1 commit into
mainfrom
claude/nice-mayer-4qkbcl

Conversation

@tdtgit

@tdtgit tdtgit commented Sep 21, 2026

Copy link
Copy Markdown
Owner

Transaction data is currently only kept as one uploaded file per transaction in the vector store, which makes date filters and totals approximate and leaves no way to correct or deduplicate a record.

Write every transaction into a D1 table in parallel with the existing upload. The vector store stays the read path, so this change only accumulates structured data; no query behaviour changes.

Schema notes:

  • Amounts are stored as integers in minor units, with the merchant-side amount kept separately when a bank settles a foreign charge in another currency.
  • The exchange rate is resolved and frozen when a transaction is recorded, so historical reports stop moving as rates change. A transaction is never blocked on a rate lookup; a daily job backfills any row recorded while no rate was available, using the rate for that row's own date.
  • An FTS5 index covers the free-text columns with diacritics folded, so untoned Vietnamese queries match.

Duplicates are handled in two layers. A unique constraint drops exact repeats from delivery retries. A merchant receipt and the matching bank debit, which arrive minutes apart under different senders, are linked through duplicate_of instead of dropped, so both stay queryable while totals count the payment once. Direction separates that case from a transfer between accounts, which produces a debit and a credit and must remain two records.

Writes are best-effort: failures are logged and never interrupt notification or the vector store upload, and the write is skipped when no binding exists.

Claude-Session: https://claude.ai/code/session_01SwuhAs5n7j6dGB3fcaqCDp

Transaction data is currently only kept as one uploaded file per transaction
in the vector store, which makes date filters and totals approximate and
leaves no way to correct or deduplicate a record.

Write every transaction into a D1 table in parallel with the existing upload.
The vector store stays the read path, so this change only accumulates
structured data; no query behaviour changes.

Schema notes:

* Amounts are stored as integers in minor units, with the merchant-side
  amount kept separately when a bank settles a foreign charge in another
  currency.
* The exchange rate is resolved and frozen when a transaction is recorded, so
  historical reports stop moving as rates change. A transaction is never
  blocked on a rate lookup; a daily job backfills any row recorded while no
  rate was available, using the rate for that row's own date.
* An FTS5 index covers the free-text columns with diacritics folded, so
  untoned Vietnamese queries match.

Duplicates are handled in two layers. A unique constraint drops exact repeats
from delivery retries. A merchant receipt and the matching bank debit, which
arrive minutes apart under different senders, are linked through duplicate_of
instead of dropped, so both stay queryable while totals count the payment
once. Direction separates that case from a transfer between accounts, which
produces a debit and a credit and must remain two records.

Writes are best-effort: failures are logged and never interrupt notification
or the vector store upload, and the write is skipped when no binding exists.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SwuhAs5n7j6dGB3fcaqCDp
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
mine-personal-accounting c97c029 Commit Preview URL

Branch Preview URL
Sep 21 2026, 07:57 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants