Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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()
Expand Down