fix(store): enforce sighting finding id invariant

This commit is contained in:
Hiten Shah
2026-05-16 22:57:32 -07:00
parent 92d65723e4
commit 375fd0bcc0
2 changed files with 6 additions and 1 deletions
+1 -1
View File
@@ -163,7 +163,7 @@ MIGRATIONS: Dict[int, str] = {
2: """ 2: """
CREATE TABLE IF NOT EXISTS finding_sightings ( CREATE TABLE IF NOT EXISTS finding_sightings (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
finding_id INTEGER REFERENCES findings(id) ON DELETE CASCADE, finding_id INTEGER NOT NULL REFERENCES findings(id) ON DELETE CASCADE,
run_id INTEGER REFERENCES research_runs(id) ON DELETE CASCADE, run_id INTEGER REFERENCES research_runs(id) ON DELETE CASCADE,
topic_id INTEGER REFERENCES topics(id) ON DELETE CASCADE, topic_id INTEGER REFERENCES topics(id) ON DELETE CASCADE,
source TEXT NOT NULL, source TEXT NOT NULL,
+5
View File
@@ -451,9 +451,14 @@ def test_init_db_creates_finding_sightings_table(temp_db):
table = conn.execute( table = conn.execute(
"SELECT name FROM sqlite_master WHERE type='table' AND name='finding_sightings'" "SELECT name FROM sqlite_master WHERE type='table' AND name='finding_sightings'"
).fetchone() ).fetchone()
columns = {
row[1]: row[3]
for row in conn.execute("PRAGMA table_info(finding_sightings)").fetchall()
}
conn.close() conn.close()
assert table is not None assert table is not None
assert columns["finding_id"] == 1
def test_store_findings_records_sightings_for_new_findings(temp_db): def test_store_findings_records_sightings_for_new_findings(temp_db):