feat: add animal tagging projection and service

Implement AnimalTagged and AnimalTagEnded event handling:
- Add migration for tag_suggestions table
- Create TagProjection for tag intervals and suggestions
- Update EventAnimalsProjection to handle tag events
- Add add_tag() and end_tag() to AnimalService

Key behaviors:
- No-op idempotence (adding active tag or ending inactive tag)
- Updates live_animals_by_location.tags JSON array
- Tracks tag usage statistics in tag_suggestions

🤖 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 07:51:20 +00:00
parent 3583285336
commit 0511ed7bca
5 changed files with 893 additions and 1 deletions

View File

@@ -0,0 +1,15 @@
-- ABOUTME: Migration to create tag_suggestions table.
-- ABOUTME: Tracks tag usage for autocomplete in the UI.
-- Tag suggestions for autocomplete
-- Updated synchronously during tagging operations
CREATE TABLE tag_suggestions (
tag TEXT PRIMARY KEY,
total_assignments INTEGER NOT NULL DEFAULT 0,
active_animals INTEGER NOT NULL DEFAULT 0,
last_used_utc INTEGER,
updated_at_utc INTEGER NOT NULL
);
-- Index for sorting by popularity
CREATE INDEX idx_tag_suggestions_popularity ON tag_suggestions(active_animals DESC, total_assignments DESC);