update check active
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlite3
|
||||
from collections.abc import Iterator
|
||||
from contextlib import contextmanager
|
||||
from pathlib import Path
|
||||
|
||||
from app.config import settings
|
||||
@@ -55,6 +57,8 @@ CREATE TABLE IF NOT EXISTS installed_components (
|
||||
package_name TEXT,
|
||||
package_version TEXT,
|
||||
service_name TEXT,
|
||||
service_check_status TEXT DEFAULT 'not-checked',
|
||||
service_checks_json TEXT,
|
||||
docker_image TEXT,
|
||||
docker_digest TEXT,
|
||||
container_name TEXT,
|
||||
@@ -75,6 +79,8 @@ CREATE TABLE IF NOT EXISTS task_components (
|
||||
progress INTEGER DEFAULT 0,
|
||||
current_step TEXT,
|
||||
error_message TEXT,
|
||||
service_check_status TEXT DEFAULT 'not-checked',
|
||||
service_checks_json TEXT,
|
||||
started_at TEXT,
|
||||
finished_at TEXT,
|
||||
FOREIGN KEY (task_id) REFERENCES tasks(id) ON DELETE CASCADE
|
||||
@@ -96,10 +102,18 @@ def _ensure_column(connection: sqlite3.Connection, table: str, column: str, defi
|
||||
connection.execute(f"ALTER TABLE {table} ADD COLUMN {column} {definition}")
|
||||
|
||||
|
||||
def get_connection() -> sqlite3.Connection:
|
||||
@contextmanager
|
||||
def get_connection() -> Iterator[sqlite3.Connection]:
|
||||
connection = sqlite3.connect(settings.db_path, timeout=30)
|
||||
connection.row_factory = sqlite3.Row
|
||||
return connection
|
||||
try:
|
||||
yield connection
|
||||
connection.commit()
|
||||
except Exception:
|
||||
connection.rollback()
|
||||
raise
|
||||
finally:
|
||||
connection.close()
|
||||
|
||||
|
||||
def initialize_database() -> None:
|
||||
@@ -110,3 +124,17 @@ def initialize_database() -> None:
|
||||
with get_connection() as connection:
|
||||
connection.executescript(SCHEMA)
|
||||
_ensure_column(connection, "installed_apps", "open_url", "TEXT")
|
||||
_ensure_column(
|
||||
connection,
|
||||
"installed_components",
|
||||
"service_check_status",
|
||||
"TEXT DEFAULT 'not-checked'",
|
||||
)
|
||||
_ensure_column(connection, "installed_components", "service_checks_json", "TEXT")
|
||||
_ensure_column(
|
||||
connection,
|
||||
"task_components",
|
||||
"service_check_status",
|
||||
"TEXT DEFAULT 'not-checked'",
|
||||
)
|
||||
_ensure_column(connection, "task_components", "service_checks_json", "TEXT")
|
||||
|
||||
Reference in New Issue
Block a user