Compare commits
No commits in common. "0b8c041ee559af903d6aa1526ed1a59753ab775d" and "6d1f8f7f1baa7efc26b0964af041af97347cb491" have entirely different histories.
0b8c041ee5
...
6d1f8f7f1b
1 changed files with 2 additions and 29 deletions
|
|
@ -1,32 +1,5 @@
|
|||
import datetime as dt
|
||||
from pathlib import Path
|
||||
from .tools import get_db_file
|
||||
import pandas as pd
|
||||
import sqlite3
|
||||
|
||||
|
||||
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)
|
||||
|
||||
def check_time_validity(created_at: dt.datetime, updated_at: dt.datetime) -> bool:
|
||||
return not (created_at > updated_at)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue