Create a timestamped database backup before mutating any records.
(db_path: Path = DB_PATH, backup_dir: Path = BACKUP_DIR)
| 45 | |
| 46 | |
| 47 | def backup_database(db_path: Path = DB_PATH, backup_dir: Path = BACKUP_DIR) -> Path: |
| 48 | """Create a timestamped database backup before mutating any records.""" |
| 49 | if not db_path.exists(): |
| 50 | raise FileNotFoundError(f"Database file not found: {db_path}") |
| 51 | |
| 52 | backup_dir.mkdir(parents=True, exist_ok=True) |
| 53 | timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") |
| 54 | backup_path = backup_dir / f"paperflow_{timestamp}.db" |
| 55 | shutil.copy2(db_path, backup_path) |
| 56 | return backup_path |
| 57 | |
| 58 | |
| 59 | def get_connection(db_path: Path = DB_PATH) -> sqlite3.Connection: |
no test coverage detected