Files
gitlore/migrations/018_fix_assignees_composite_index.sql
Taylor Eernisse 121a634653 fix: critical data integrity — timeline dedup, discussion atomicity, index collision
Three correctness bugs found via peer code review:

1. TimelineEvent PartialEq/Ord omitted entity_type — issue #42 and MR #42
   with the same timestamp and event_type were treated as equal. In a
   BTreeSet or dedup, one would silently be dropped. Added entity_type to
   both PartialEq and Ord comparisons.

2. discussions.rs: store_payload() was called outside the transaction
   (on bare conn) while upsert_discussion/notes were inside. A crash
   between them left orphaned payload rows. Moved store_payload inside
   the unchecked_transaction block, matching mr_discussions.rs pattern.

3. Migration 017 created idx_issue_assignees_username(username, issue_id)
   but migration 005 already created the same index name with just
   (username). SQLite's IF NOT EXISTS silently skipped the composite
   version on every existing database. New migration 018 drops and
   recreates the index with correct composite columns.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 07:54:59 -05:00

11 lines
580 B
SQL

-- Migration 018: Fix composite index on issue_assignees
-- Migration 005 created idx_issue_assignees_username(username) as single-column.
-- Migration 017 attempted to recreate as (username, issue_id) but IF NOT EXISTS
-- silently skipped it. Drop and recreate with the correct composite columns.
DROP INDEX IF EXISTS idx_issue_assignees_username;
CREATE INDEX idx_issue_assignees_username ON issue_assignees(username, issue_id);
INSERT INTO schema_version (version, applied_at, description)
VALUES (18, strftime('%s', 'now') * 1000, 'Fix composite index on issue_assignees');