From 0c1c1c6792f3076508cb9d43cece815a78c6f6c5 Mon Sep 17 00:00:00 2001 From: Cameron Cordes Date: Wed, 27 May 2026 22:34:44 -0400 Subject: [PATCH] fix: split token count columns into separate migration A previous commit added prompt_eval_count and eval_count to the existing 2026-05-27-000002_add_insight_generation_params migration, but Diesel won't re-run an already-applied migration. Environments that applied the original version of 000002 never got these two columns, causing "no such column: photo_insights.prompt_eval_count" on every insight read. - Revert 000002 up.sql to its original 7-column form - Add 000003_add_insight_token_counts for the two missing columns Co-Authored-By: Claude Opus 4.7 (1M context) --- .../up.sql | 4 +--- .../down.sql | 13 +++++++++++++ .../up.sql | 6 ++++++ 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 migrations/2026-05-27-000003_add_insight_token_counts/down.sql create mode 100644 migrations/2026-05-27-000003_add_insight_token_counts/up.sql diff --git a/migrations/2026-05-27-000002_add_insight_generation_params/up.sql b/migrations/2026-05-27-000002_add_insight_generation_params/up.sql index c44f568..1313fde 100644 --- a/migrations/2026-05-27-000002_add_insight_generation_params/up.sql +++ b/migrations/2026-05-27-000002_add_insight_generation_params/up.sql @@ -1,4 +1,4 @@ --- Persist generation parameters and token usage on each insight row. +-- Persist generation parameters on each insight row for auditing. ALTER TABLE photo_insights ADD COLUMN num_ctx INTEGER; ALTER TABLE photo_insights ADD COLUMN temperature REAL; ALTER TABLE photo_insights ADD COLUMN top_p REAL; @@ -6,5 +6,3 @@ ALTER TABLE photo_insights ADD COLUMN top_k INTEGER; ALTER TABLE photo_insights ADD COLUMN min_p REAL; ALTER TABLE photo_insights ADD COLUMN system_prompt TEXT; ALTER TABLE photo_insights ADD COLUMN persona_id TEXT; -ALTER TABLE photo_insights ADD COLUMN prompt_eval_count INTEGER; -ALTER TABLE photo_insights ADD COLUMN eval_count INTEGER; diff --git a/migrations/2026-05-27-000003_add_insight_token_counts/down.sql b/migrations/2026-05-27-000003_add_insight_token_counts/down.sql new file mode 100644 index 0000000..f680ad2 --- /dev/null +++ b/migrations/2026-05-27-000003_add_insight_token_counts/down.sql @@ -0,0 +1,13 @@ +-- SQLite doesn't support DROP COLUMN before 3.35.0; recreate the table +-- without the token-count columns. This is only needed for rollback. +CREATE TABLE photo_insights_old AS + SELECT id, library_id, rel_path, title, summary, generated_at, + model_version, is_current, training_messages, approved, + backend, fewshot_source_ids, content_hash, + num_ctx, temperature, top_p, top_k, min_p, + system_prompt, persona_id + FROM photo_insights; + +DROP TABLE photo_insights; + +ALTER TABLE photo_insights_old RENAME TO photo_insights; diff --git a/migrations/2026-05-27-000003_add_insight_token_counts/up.sql b/migrations/2026-05-27-000003_add_insight_token_counts/up.sql new file mode 100644 index 0000000..ce8890e --- /dev/null +++ b/migrations/2026-05-27-000003_add_insight_token_counts/up.sql @@ -0,0 +1,6 @@ +-- Persist token usage on each insight row. Split from +-- 2026-05-27-000002_add_insight_generation_params because that +-- migration was already applied on some environments before these +-- columns were added. +ALTER TABLE photo_insights ADD COLUMN prompt_eval_count INTEGER; +ALTER TABLE photo_insights ADD COLUMN eval_count INTEGER;