@@ -0,0 +1,25 @@
|
||||
"""Сверка восстановленной БД с counts и пятью полными строками из эксперимента."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import psycopg
|
||||
from psycopg import sql
|
||||
from psycopg.rows import dict_row
|
||||
from src.config import DATABASE_URL
|
||||
|
||||
expected = json.loads(Path('evidence/track2_raw.json').read_text())
|
||||
with psycopg.connect(DATABASE_URL, row_factory=dict_row) as db:
|
||||
db.execute(sql.SQL('SET search_path TO {}').format(sql.Identifier(expected['schema'])))
|
||||
counts = {}
|
||||
for table, count in expected['counts'].items():
|
||||
actual = db.execute(sql.SQL('SELECT count(*) AS n FROM {}').format(sql.Identifier(table))).fetchone()['n']
|
||||
assert actual == count, (table, actual, count)
|
||||
counts[table] = actual
|
||||
actual_samples = []
|
||||
for sample in expected['sample_messages']:
|
||||
row = db.execute('SELECT * FROM messages WHERE id=%s', (sample['id'],)).fetchone()
|
||||
actual = json.loads(json.dumps(row, default=str))
|
||||
assert actual == sample, 'Restored message differs'
|
||||
actual_samples.append(actual)
|
||||
result = {'counts': counts, 'sample_messages_matched': len(actual_samples), 'status': 'PASS'}
|
||||
Path('evidence/restore_verification.json').write_text(json.dumps(result, indent=2))
|
||||
print('PASS: restored row counts and selected full messages match backup dataset')
|
||||
Reference in New Issue
Block a user