mirror of
https://github.com/whekin/household-bot.git
synced 2026-03-31 17:54:02 +00:00
2.2 KiB
2.2 KiB
HOUSEBOT-012: V1 Accounting Schema
Summary
Define and migrate a production-ready accounting schema for household rent/utilities/purchases and settlement snapshots.
Goals
- Support all v1 finance flows in database form.
- Enforce idempotency constraints for Telegram message ingestion.
- Store all monetary values in minor integer units.
- Provide local seed fixtures for fast end-to-end development.
Non-goals
- Bot command implementation.
- Settlement algorithm implementation.
Scope
- In: Drizzle schema + generated SQL migration + seed script + runbook update.
- Out: adapter repositories and service handlers.
Interfaces and Contracts
Tables covered:
householdsmembersbilling_cyclesrent_rulesutility_billspresence_overridespurchase_entriesprocessed_bot_messagessettlementssettlement_lines
Domain Rules
- Minor-unit integer money only (
bigintcolumns) - Deterministic one-cycle settlement snapshot (
settlements.cycle_idunique) - Message idempotency enforced via unique source message keys
Data Model Changes
- Add new finance tables and indexes for read/write paths.
- Add unique indexes for idempotency and period uniqueness.
- Preserve existing household/member table shape.
Security and Privacy
- Store internal member IDs instead of personal attributes in finance tables.
- Keep raw purchase text for audit/parser debugging only.
Observability
processed_bot_messagesand settlement metadata provide traceability.
Edge Cases and Failure Modes
- Duplicate message ingestion attempts.
- Missing active cycle when writing purchases/bills.
- Partial fixture seed runs.
Test Plan
- Generate and check migration metadata.
- Typecheck db package.
- Execute seed script on migrated database.
Acceptance Criteria
bun run db:generateproduces migration SQL for schema updates.bun run db:checkpasses.- Schema supports v1 rent/utilities/purchase/settlement workflows.
- Idempotency indexes exist for Telegram ingestion.
- Migration runbook includes rollback notes.
Rollout Plan
- Apply migration in dev, run seed, validate queryability.
- Promote migration through CI/CD pipeline before production cutover.