feat: add feed inventory schema and purchase service

Implement FeedPurchased event handling:
- Add migration for feed_inventory table
- Create FeedInventoryProjection to track purchases
- Create FeedService with purchase_feed method
- Calculate price_per_kg_cents from bag details

Purchases accumulate in inventory with:
- purchased_kg, given_kg, balance_kg tracking
- Last purchase price stored in cents
- Timestamps for last purchase/given

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-29 08:02:24 +00:00
parent 7c972f31d7
commit 5c10a750ce
4 changed files with 454 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
-- ABOUTME: Migration to create feed_inventory table.
-- ABOUTME: Tracks feed purchases, amounts given, and current balance.
-- Feed inventory tracks global feed levels per type
-- Stores amounts in kg, prices in cents
CREATE TABLE feed_inventory (
feed_type_code TEXT PRIMARY KEY REFERENCES feed_types(code),
purchased_kg INTEGER NOT NULL DEFAULT 0,
given_kg INTEGER NOT NULL DEFAULT 0,
balance_kg INTEGER NOT NULL DEFAULT 0,
last_purchase_price_per_kg_cents INTEGER,
last_purchase_at_utc INTEGER,
last_given_at_utc INTEGER,
updated_at_utc INTEGER NOT NULL
);
-- Index for finding when last purchase/given occurred
CREATE INDEX idx_feed_inventory_last_on ON feed_inventory(last_purchase_at_utc, last_given_at_utc);