Restore database from backup.
(temp_path: Path, metadata: dict)
| 313 | |
| 314 | |
| 315 | def _restore_database(temp_path: Path, metadata: dict) -> None: |
| 316 | """Restore database from backup.""" |
| 317 | db_type = metadata.get("database_type", "postgresql") |
| 318 | db_file = metadata.get("database_file", "database.dump") |
| 319 | dump_file = temp_path / db_file |
| 320 | |
| 321 | if not dump_file.exists(): |
| 322 | raise ValueError(f"Invalid backup: missing {db_file}") |
| 323 | |
| 324 | current_db_type = "postgresql" if _is_postgresql() else "sqlite" |
| 325 | |
| 326 | if db_type != current_db_type: |
| 327 | raise ValueError( |
| 328 | f"Database type mismatch: backup is {db_type}, " |
| 329 | f"but current database is {current_db_type}" |
| 330 | ) |
| 331 | |
| 332 | if db_type == "postgresql": |
| 333 | _restore_postgresql(dump_file) |
| 334 | else: |
| 335 | _restore_sqlite(dump_file) |
| 336 | |
| 337 | |
| 338 | def list_backups() -> list[dict]: |
no test coverage detected