"""Restore from the most recent 'pre_migration'-tagged backup.""" from __future__ import annotations from pathlib import Path from . import backup as backup_mod class NoBackupFoundError(Exception): """Raised when rollback() is called with no pre_migration backup on disk.""" def rollback_to_pre_migration(*, db_url: str, images_root: Path) -> dict: manifest = backup_mod.find_latest_backup(images_root, tag="pre_migration") if manifest is None: raise NoBackupFoundError( "no pre_migration-tagged backup found under /_backups/" ) return backup_mod.restore_backup( manifest=manifest, db_url=db_url, images_root=images_root, )