with open('backend/app/db.py', 'r', encoding='utf-8') as f: content = f.read() new_func = '''def list_segment_edits(video_id: str) -> list[dict]: with _DB_LOCK: conn = get_conn() cur = conn.cursor() cur.execute( "SELECT * FROM segment_edits WHERE video_id = ? ORDER BY segment_key", (video_id,), ) rows = cur.fetchall() conn.close() return [_row_to_dict(row) for row in rows] def replace_segment_edits''' content = content.replace('def replace_segment_edits', new_func) with open('backend/app/db.py', 'w', encoding='utf-8') as f: f.write(content) print('db.py patched')