From 5e7e2fc695811011f53a420f7bc5c74adcaa7531 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Thu, 26 Nov 2026 13:54:26 -0500 Subject: [PATCH] Migration 5: end the stale UPS battery known condition The APC UPS was replaced by a UniFi UPS 2U Pro on 2026-08-08 (Tinker 387982348, closed 2026-09-25); the 'old battery' entry seeded in migration 3 came from Grafana silences that predate it. Ended, not deleted, so the history stays. Co-Authored-By: Claude Opus 5.5 --- tests/test_db_mariadb.py | 10 ++++++---- thor/db.py | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/test_db_mariadb.py b/tests/test_db_mariadb.py index 1defebf..d2dcd03 100644 --- a/tests/test_db_mariadb.py +++ b/tests/test_db_mariadb.py @@ -105,14 +105,16 @@ def test_known_conditions_seeded_and_managed(db): db.migrate() s = Store(db) seeded = s.known_conditions() + # The UPS battery entry is seeded by migration 3 and ended by migration 5 (UPS replaced). assert [(k['kind'], k['subject'], k['ticket_id']) for k in seeded] == [ - ('reboot', 'compute-storage-02', '693930698'), ('ceph_flag', 'noout', '693930698'), - ('ups_battery', 'ups', None)] + ('reboot', 'compute-storage-02', '693930698'), ('ceph_flag', 'noout', '693930698')] + ended = db.query("SELECT ended_by FROM known_conditions WHERE kind='ups_battery'") + assert ended == [{'ended_by': 'operator: UPS replaced (Tinker 387982348)'}] new = s.add_known_condition('reboot', 'pbs', '1', 'testing', 'jared', 1795410668.0) - assert len(s.known_conditions()) == 4 + assert len(s.known_conditions()) == 3 assert s.end_known_condition(new, 'jared', 1795410700.0) == 1 assert s.end_known_condition(new, 'jared', 1795410700.0) == 0 - assert len(s.known_conditions()) == 3 + assert len(s.known_conditions()) == 2 s.save_incident({'key': 'k', 'state': 'pending', 'priority': 3, 'kind': 'x', 'subject': 's', 'mode': 'shadow', 'first_seen': 1.0, 'last_seen': 1.0}, 2.0) s.delete_incident('k') diff --git a/thor/db.py b/thor/db.py index 22b2f98..f203c91 100644 --- a/thor/db.py +++ b/thor/db.py @@ -161,6 +161,13 @@ MIGRATIONS: List[str] = [ KEY idx_links_incident (incident_key, removed_at) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; """, + # 5: the UPS battery known condition was stale: the APC unit was replaced by a UniFi UPS 2U + # Pro on 2026-08-08 (Tinker 387982348, closed 2026-09-25). End it, keep the history. + """ + UPDATE known_conditions SET ended_at=UTC_TIMESTAMP(3), + ended_by='operator: UPS replaced (Tinker 387982348)' + WHERE kind='ups_battery' AND ended_at IS NULL; + """, ]