Files
animaltrack/migrations/0007-egg-stats-30d.sql
Petru Paler 25a91c3322 fix: remove trailing newlines from migrations to prevent SQLITE_MISUSE errors
Python's sqlite3.executescript() has a bug where trailing newlines after
the final semicolon create empty statements. When APSW's log_sqlite() is
enabled (via apswutils, imported by fastmigrate), these cause visible
"API called with NULL prepared statement" errors during interpreter shutdown.

- Strip trailing newlines from all 9 existing migration files
- Update migration template to end with semicolon, no trailing newline
- Document the requirement in CLAUDE.md

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 16:09:06 +00:00

22 lines
915 B
SQL

-- ABOUTME: Migration to create egg_stats_30d_by_location table.
-- ABOUTME: Caches computed 30-day rolling statistics for egg production.
-- Egg stats computed on-read and cached per location
-- Feed amounts in grams (not kg) for precision
-- Costs stored as REAL EUR values
CREATE TABLE egg_stats_30d_by_location (
location_id TEXT PRIMARY KEY REFERENCES locations(id),
window_start_utc INTEGER NOT NULL,
window_end_utc INTEGER NOT NULL,
eggs_total_pcs INTEGER NOT NULL,
feed_total_g INTEGER NOT NULL,
feed_layers_g INTEGER NOT NULL,
cost_per_egg_all_eur REAL NOT NULL,
cost_per_egg_layers_eur REAL NOT NULL,
layer_eligible_bird_days INTEGER NOT NULL,
layer_eligible_count_now INTEGER NOT NULL,
updated_at_utc INTEGER NOT NULL
);
-- Index for finding stale stats that need recomputation
CREATE INDEX idx_egg_stats_updated ON egg_stats_30d_by_location(updated_at_utc);