✨feature: Add editable hostname and operating system
Release / Build and Push Docker Image (push) Successful in 4m56s
Release / Build and Push Docker Image (push) Successful in 4m56s
This commit is contained in:
@@ -22,9 +22,11 @@ CREATE TABLE IF NOT EXISTS devices (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
ip TEXT NOT NULL UNIQUE,
|
||||
hostname TEXT,
|
||||
custom_hostname TEXT,
|
||||
mac TEXT,
|
||||
vendor TEXT,
|
||||
os_name TEXT,
|
||||
custom_os_name TEXT,
|
||||
first_seen TEXT NOT NULL,
|
||||
last_seen TEXT NOT NULL,
|
||||
is_active INTEGER NOT NULL DEFAULT 1,
|
||||
@@ -61,6 +63,15 @@ def init_db() -> None:
|
||||
db_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
with sqlite3.connect(DB_PATH) as conn:
|
||||
conn.executescript(SCHEMA)
|
||||
ensure_column(conn, "devices", "custom_hostname", "TEXT")
|
||||
ensure_column(conn, "devices", "custom_os_name", "TEXT")
|
||||
|
||||
|
||||
def ensure_column(conn: sqlite3.Connection, table: str, column: str, definition: str) -> None:
|
||||
existing = conn.execute(f"PRAGMA table_info({table})").fetchall()
|
||||
column_names = {row[1] for row in existing}
|
||||
if column not in column_names:
|
||||
conn.execute(f"ALTER TABLE {table} ADD COLUMN {column} {definition}")
|
||||
|
||||
|
||||
@contextmanager
|
||||
|
||||
Reference in New Issue
Block a user