Compare commits

..

2 commits

Author SHA1 Message Date
0b8c041ee5
add wrapper functions to check for the validity of the database
Some checks failed
Mypy / mypy (push) Failing after 1m16s
Pytest / pytest (3.12) (push) Failing after 1m14s
Pytest / pytest (3.13) (push) Failing after 1m6s
Pytest / pytest (3.14) (push) Failing after 1m9s
Ruff / ruff (push) Failing after 1m0s
2026-04-14 15:34:05 +02:00
91938c3c5a
add second time integrity check 2026-04-14 14:17:41 +02:00

View file

@ -1,5 +1,32 @@
import datetime as dt
from pathlib import Path
from .tools import get_db_file
import pandas as pd
import sqlite3
def check_time_validity(created_at: dt.datetime, updated_at: dt.datetime) -> bool:
return not (created_at > updated_at)
def has_valid_times(result: pd.DataFrame) -> bool:
# we expect created_at <= updated_at <= now
created_at = dt.datetime.fromisoformat(result['created_at'])
updated_at = dt.datetime.fromisoformat(result['updated_at'])
if created_at > updated_at:
return False
if updated_at > dt.datetime.now():
return False
return True
def check_db_integrity(path: Path) -> None:
db = get_db_file(path)
search_expr = "SELECT * FROM 'backlogs'"
conn = sqlite3.connect(db)
results = pd.read_sql(search_expr, conn)
for result in results:
if not has_valid_times(result):
raise ValueError(f"Result with id {result[id]} has wrong time signatures.")
def full_integrity_check(path: Path) -> None:
check_db_integrity(path)