fix server - agent
This commit is contained in:
@@ -38,6 +38,7 @@ CREATE TABLE IF NOT EXISTS installed_apps (
|
||||
app_id TEXT PRIMARY KEY,
|
||||
app_name TEXT NOT NULL,
|
||||
version TEXT NOT NULL,
|
||||
open_url TEXT,
|
||||
manifest_hash TEXT,
|
||||
status TEXT NOT NULL,
|
||||
installed_at TEXT NOT NULL,
|
||||
@@ -86,6 +87,15 @@ CREATE TABLE IF NOT EXISTS agent_config (
|
||||
"""
|
||||
|
||||
|
||||
def _ensure_column(connection: sqlite3.Connection, table: str, column: str, definition: str) -> None:
|
||||
columns = {
|
||||
row["name"]
|
||||
for row in connection.execute(f"PRAGMA table_info({table})").fetchall()
|
||||
}
|
||||
if column not in columns:
|
||||
connection.execute(f"ALTER TABLE {table} ADD COLUMN {column} {definition}")
|
||||
|
||||
|
||||
def get_connection() -> sqlite3.Connection:
|
||||
connection = sqlite3.connect(settings.db_path, timeout=30)
|
||||
connection.row_factory = sqlite3.Row
|
||||
@@ -99,4 +109,4 @@ def initialize_database() -> None:
|
||||
settings.log_dir.mkdir(parents=True, exist_ok=True)
|
||||
with get_connection() as connection:
|
||||
connection.executescript(SCHEMA)
|
||||
|
||||
_ensure_column(connection, "installed_apps", "open_url", "TEXT")
|
||||
|
||||
@@ -160,7 +160,7 @@ class Repository:
|
||||
with get_connection() as connection:
|
||||
rows = connection.execute(
|
||||
"""
|
||||
SELECT app_id, app_name, version, manifest_hash, status, installed_at, updated_at
|
||||
SELECT app_id, app_name, version, open_url, manifest_hash, status, installed_at, updated_at
|
||||
FROM installed_apps
|
||||
ORDER BY app_name ASC
|
||||
"""
|
||||
@@ -173,22 +173,24 @@ class Repository:
|
||||
app_name: str,
|
||||
version: str,
|
||||
manifest_hash: str | None,
|
||||
open_url: str | None = None,
|
||||
status: str = "installed",
|
||||
) -> None:
|
||||
now = utc_now()
|
||||
with get_connection() as connection:
|
||||
connection.execute(
|
||||
"""
|
||||
INSERT INTO installed_apps (app_id, app_name, version, manifest_hash, status, installed_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
INSERT INTO installed_apps (app_id, app_name, version, open_url, manifest_hash, status, installed_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(app_id) DO UPDATE SET
|
||||
app_name = excluded.app_name,
|
||||
version = excluded.version,
|
||||
open_url = excluded.open_url,
|
||||
manifest_hash = excluded.manifest_hash,
|
||||
status = excluded.status,
|
||||
updated_at = excluded.updated_at
|
||||
""",
|
||||
(app_id, app_name, version, manifest_hash, status, now, now),
|
||||
(app_id, app_name, version, open_url, manifest_hash, status, now, now),
|
||||
)
|
||||
|
||||
def delete_installed_app(self, app_id: str) -> None:
|
||||
@@ -252,4 +254,3 @@ class Repository:
|
||||
|
||||
def export_manifest_hash(self, manifest: dict[str, Any]) -> str:
|
||||
return json.dumps(manifest, sort_keys=True, separators=(",", ":"))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user