From 3a89cb62aa955044b5e5822cc15ba56c2aaba4fc Mon Sep 17 00:00:00 2001 From: ashleigh-byte <252663029+ashleigh-byte@users.noreply.github.com> Date: Wed, 29 Jul 2026 16:04:51 +0100 Subject: [PATCH] Add mac/vendor/hostname columns to device_scans Pure schema change with no consumers yet: nmap-derived MAC address, vendor, and hostname data will be tracked per device scan starting in a follow-up PR. Existing databases auto-migrate in place via _migrate_device_scans_columns() so upgrading doesn't require recreating the database. --- sqlite.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/sqlite.py b/sqlite.py index a43a214..283a20d 100644 --- a/sqlite.py +++ b/sqlite.py @@ -56,9 +56,13 @@ def _create_schema(self): CREATE TABLE IF NOT EXISTS device_scans ( id TEXT PRIMARY KEY, ips TEXT NOT NULL, - latencies TEXT NOT NULL + latencies TEXT NOT NULL, + macs TEXT NOT NULL DEFAULT '[]', + vendors TEXT NOT NULL DEFAULT '[]', + hostnames TEXT NOT NULL DEFAULT '[]' ); """) + self._migrate_device_scans_columns() self.conn.execute(""" CREATE TABLE IF NOT EXISTS speedtest ( @@ -68,6 +72,18 @@ def _create_schema(self): ); """) + def _migrate_device_scans_columns(self): + # Databases created before mac/vendor/hostname tracking was added + # won't have these columns yet; add them in place so upgrading + # doesn't require recreating the database. + cursor = self.conn.execute("PRAGMA table_info(device_scans)") + existing_cols = {row[1] for row in cursor.fetchall()} + for col in ("macs", "vendors", "hostnames"): + if col not in existing_cols: + self.conn.execute( + f"ALTER TABLE device_scans ADD COLUMN {col} TEXT NOT NULL DEFAULT '[]'" + ) + @contextmanager def transaction(self): depth = _tx_depth.get()