Deduplicate DatabaseJanitor codebase after async introduction#1366
Deduplicate DatabaseJanitor codebase after async introduction#1366tboy1337 wants to merge 3 commits into
Conversation
- Introduced a common base class, BaseDatabaseJanitor, to reduce code duplication. - Removed the _JanitorConfig dataclass and related functions, simplifying the initialization process. - Updated DatabaseJanitor and AsyncDatabaseJanitor to directly assign configuration attributes. - Enhanced SQL query building methods for better readability and maintainability. - Improved overall structure and clarity of the janitor classes.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe refactor adds ChangesDatabaseJanitor deduplication
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…classes - Updated `BaseDatabaseJanitor`, `DatabaseJanitor`, and `AsyncDatabaseJanitor` to use the `is_template()` method for checking template status instead of the `as_template` attribute. - Improved code clarity and maintainability by standardizing the method used for template checks across the janitor classes.
Follow-up refactor after #1295 introduced
AsyncDatabaseJanitoralongside the existing syncDatabaseJanitor.This PR consolidates shared janitor logic into a new
BaseDatabaseJanitorbase class:__init__with version parsing and configuration assignmentis_template()implementation_build_create_database_sql()for CREATE DATABASE DDL constructionDatabaseJanitorandAsyncDatabaseJanitornow inherit fromBaseDatabaseJanitor, removing the_JanitorConfigdataclass,_JanitorConfigTargetprotocol, and related helper functions (_init_janitor_config,_apply_janitor_config, module-level_build_create_database_sql).Sync/async-specific methods (
init,drop,cursor,load, and connection helpers) remain in their respective subclasses, since they require separate sync and async implementations.This builds on the intent of #1364 and closes the remaining small deduplication gap by hoisting
is_template()into the base class and keeping explicit type annotations.Changes
pytest_postgresql/janitor.py— introduceBaseDatabaseJanitor; slim down sync/async subclassesnewsfragments/+dedupe-janitor.misc.rst— changelog entryNo public API changes:
DatabaseJanitorandAsyncDatabaseJanitorconstructors and behavior are unchanged.Summary by CodeRabbit