Skip to content

Refactor: Separate DB backup into standalone tool - #192

Merged
RyanTheRobothead merged 13 commits into
db_migrationsfrom
backup_tooling
Dec 4, 2025
Merged

Refactor: Separate DB backup into standalone tool#192
RyanTheRobothead merged 13 commits into
db_migrationsfrom
backup_tooling

Conversation

@RyanTheRobothead

@RyanTheRobothead RyanTheRobothead commented Nov 30, 2025

Copy link
Copy Markdown
Member

PR Info

  • Separate out database backup and restore tooling into a standalone tool that's used by the migration handling.
  • Adds a dedicated madsci-backup CLI command to madsci.common

Developer Checklists

I have:

  • Run Pre-commit and Unit Tests, and ensured that they pass
  • Created or updated documentation relevant to your change
  • Created or updated unit tests relevant to your change

@RyanTheRobothead RyanTheRobothead changed the title Backup tooling Refactor: Separate DB backup into standalone tool Nov 30, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR successfully refactors database backup and restore functionality from being embedded within migration tools to standalone, reusable backup tools. The changes improve code organization, maintainability, and testability through composition over inheritance.

Key changes:

  • Created standalone PostgreSQLBackupTool and MongoDBBackupTool classes with comprehensive backup, restore, validation, and management capabilities
  • Refactored migration tools to use composition with backup tools via backup_tool attribute instead of embedded backup methods
  • Added CLI interfaces for both PostgreSQL and MongoDB backup tools with commands for create, restore, validate, list, and delete operations
  • Removed 572 lines of duplicated backup validation code

Reviewed changes

Copilot reviewed 41 out of 42 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/madsci_common/madsci/common/backup_tools/ New standalone backup tool implementations with PostgreSQL and MongoDB support, including validators, managers, and CLI interfaces
src/madsci_common/madsci/common/types/backup_types.py New backup configuration types for PostgreSQL and MongoDB
src/madsci_resource_manager/madsci/resource_manager/migration_tool.py Refactored to use PostgreSQLBackupTool composition, removing 443 lines of embedded backup code
src/madsci_common/madsci/common/mongodb_migration_tool.py Refactored to use MongoDBBackupTool composition, removing 352 lines of embedded backup code
src/**/tests/ Updated test files to mock backup_tool attribute instead of direct backup methods
src/madsci_common/tests/test_backup_tools/ Comprehensive new test suites for backup tools, validators, managers, and CLIs
src/madsci_common/pyproject.toml Added CLI entry points and new dependencies (psycopg2-binary, click)
src/madsci_data_manager/madsci/data_manager/schema.json Schema version bump and index removal (unrelated to backup refactoring)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/madsci_data_manager/madsci/data_manager/schema.json
@github-actions

github-actions Bot commented Nov 30, 2025

Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  src/madsci_common/madsci/common
  mongodb_migration_tool.py 122-123, 127, 263-264
  src/madsci_common/madsci/common/backup_tools
  __init__.py
  backup_manager.py 63-64, 109-111, 133, 149-150, 159-160, 190, 231, 247, 284, 287-288, 304-305, 321-322, 351-356
  backup_validator.py 105-107, 176-178, 256, 269-273, 287
  base_backup.py
  cli.py 110, 160-170, 174-176, 214-224, 233-234, 239, 243
  mongo_cli.py 18-19, 59, 150-152, 202-203, 225-226, 239-240, 262-264, 269, 273
  mongodb_backup.py 47, 82-84, 140, 149-168, 204, 209, 249-256, 284, 304-305, 326-328, 336, 358, 363, 368-369, 403, 428-430, 434-482, 515-540, 544-553, 559-560
  postgres_backup.py 12, 128-134, 196, 204-205, 207, 262, 275, 277, 279, 290-296, 303, 330, 356, 360, 373-374, 407-419, 441-442, 456-458, 473-475, 488-494, 506-508
  postgres_cli.py 109-111, 162-163, 179-180
  src/madsci_common/madsci/common/types
  __init__.py
  backup_types.py
  base_types.py 45
  src/madsci_resource_manager/madsci/resource_manager
  database_version_checker.py
  migration_tool.py 302-303, 553
Project Total  

This report was generated by python-coverage-comment-action

@RyanTheRobothead RyanTheRobothead added the enhancement New feature or request label Dec 2, 2025
@RyanTheRobothead RyanTheRobothead self-assigned this Dec 2, 2025
Comment thread src/madsci_common/madsci/common/backup_tools/backup_validator.py

@Dozgulbas Dozgulbas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks very nice! Curios about the usage of some of the parts. Also do you foresee that the backup tooling can be used other than DB migration backups?

Comment thread src/madsci_common/madsci/common/backup_tools/cli.py
Comment thread src/madsci_common/madsci/common/backup_tools/unified_cli.py Outdated
@RyanTheRobothead
RyanTheRobothead merged commit f89b680 into db_migrations Dec 4, 2025
4 checks passed
@RyanTheRobothead
RyanTheRobothead deleted the backup_tooling branch December 27, 2025 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants