diff --git a/sfm/database.py b/sfm/database.py index 464c2b5..91a0bfc 100644 --- a/sfm/database.py +++ b/sfm/database.py @@ -81,6 +81,7 @@ CREATE TABLE IF NOT EXISTS events ( sample_rate INTEGER, record_type TEXT, -- "single_shot" | "continuous" false_trigger INTEGER NOT NULL DEFAULT 0, -- 0=no, 1=yes (manual flag) + reviewed_real INTEGER NOT NULL DEFAULT 0, -- 0=no, 1=operator-confirmed real (mutually exclusive with false_trigger) blastware_filename TEXT, -- event file within waveform store; extension is per-event (AB0T encodes timestamp) blastware_filesize INTEGER, -- bytes; NULL if no event file saved a5_pickle_filename TEXT, -- ".a5.pkl" sidecar @@ -188,6 +189,7 @@ class SeismoDb: sample_rate INTEGER, record_type TEXT, false_trigger INTEGER NOT NULL DEFAULT 0, + reviewed_real INTEGER NOT NULL DEFAULT 0, created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')), UNIQUE(serial, timestamp) ); @@ -224,6 +226,7 @@ class SeismoDb: ("shape_near_peak_count", "INTEGER"), ("shape_sample_count", "INTEGER"), ("shape_axis", "TEXT"), + ("reviewed_real", "INTEGER NOT NULL DEFAULT 0"), ): if col not in existing_cols: log.info("_migrate: events ADD COLUMN %s %s", col, ddl) diff --git a/tests/test_reviewed_real_column.py b/tests/test_reviewed_real_column.py new file mode 100644 index 0000000..3fe153b --- /dev/null +++ b/tests/test_reviewed_real_column.py @@ -0,0 +1,14 @@ +import sqlite3 +from sfm.database import SeismoDb +def _cols(db): + with sqlite3.connect(db.db_path) as c: + return {r[1] for r in c.execute("PRAGMA table_info(events)")} +def test_fresh_db_has_reviewed_real(tmp_path): + assert "reviewed_real" in _cols(SeismoDb(tmp_path/"s.db")) +def test_existing_db_migrates_reviewed_real(tmp_path): + p = tmp_path/"s.db"; db = SeismoDb(p) + with sqlite3.connect(p) as c: + c.execute("ALTER TABLE events DROP COLUMN reviewed_real") + assert "reviewed_real" not in _cols(db) # dropped (read via existing handle/connection) + SeismoDb(p) # re-open migrates + assert "reviewed_real" in _cols(SeismoDb(p))