feat(reports): store and browse report artifacts
This commit is contained in:
1 parent
5967a43eb5
commit
6f2e479958
13 files changed
+875
-93
No files matched your search
+24
-8
@@ -14,7 +14,7 @@ import sqlite3
|
||||
from typing import Iterable
|
||||
|
||||
#: Latest schema version. Bump by one whenever a new migration is appended.
|
||||
SCHEMA_VERSION = 1
|
||||
SCHEMA_VERSION = 2
|
||||
|
||||
#: Ordered migrations: index -> list of DDL statements. A migration N upgrades a
|
||||
#: database from user_version N-1 to N. Never edit an older migration in place;
|
||||
@@ -31,14 +31,29 @@ MIGRATIONS: dict[int, list[str]] = {
|
||||
log_path TEXT,
|
||||
enabled INTEGER NOT NULL DEFAULT 1
|
||||
)
|
||||
""",
|
||||
"""
|
||||
INSERT OR IGNORE INTO log_sources (name, log_path)
|
||||
VALUES ('copyparty', NULL), ('npm', NULL)
|
||||
],
|
||||
|
||||
2: [
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS report_artifacts (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
source TEXT NOT NULL,
|
||||
scan_id INTEGER,
|
||||
report_type TEXT NOT NULL,
|
||||
generated_at TEXT NOT NULL,
|
||||
schema_version INTEGER NOT NULL DEFAULT 1,
|
||||
payload_json TEXT NOT NULL,
|
||||
original_path TEXT NOT NULL,
|
||||
content_sha256 TEXT NOT NULL,
|
||||
created_at TEXT NOT NULL,
|
||||
UNIQUE (original_path, content_sha256)
|
||||
)
|
||||
""",
|
||||
# ------------------------------------------------------------------
|
||||
# requests — one row per parsed request; insert-only
|
||||
# ------------------------------------------------------------------
|
||||
"CREATE INDEX IF NOT EXISTS idx_report_artifacts_source_time "
|
||||
"ON report_artifacts (source, generated_at DESC, id DESC)",
|
||||
"CREATE INDEX IF NOT EXISTS idx_report_artifacts_type_time "
|
||||
"ON report_artifacts (report_type, generated_at DESC, id DESC)",
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS requests (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
@@ -261,7 +276,8 @@ def apply_migrations(conn: sqlite3.Connection) -> None:
|
||||
for version in range(current + 1, SCHEMA_VERSION + 1):
|
||||
statements = MIGRATIONS.get(version)
|
||||
if statements is None:
|
||||
raise RuntimeError(f"missing migration for schema version {version}")
|
||||
raise RuntimeError(
|
||||
f"missing migration for schema version {version}")
|
||||
with conn:
|
||||
for ddl in statements:
|
||||
conn.execute(ddl)
|
||||
|
||||
Reference in new issue
Block a user