Skip to content

Deduplicate DatabaseJanitor codebase after async introduction#1364

Open
fizyk wants to merge 1 commit into
mainfrom
deduplicate-janitor
Open

Deduplicate DatabaseJanitor codebase after async introduction#1364
fizyk wants to merge 1 commit into
mainfrom
deduplicate-janitor

Conversation

@fizyk

@fizyk fizyk commented Jul 14, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Refactor

    • Streamlined database janitor behaviour across synchronous and asynchronous workflows.
    • Improved consistency in database creation and configuration handling.
    • Existing janitor functionality remains available while reducing duplicated behaviour.
  • Documentation

    • Added a changelog entry covering the codebase improvements following the introduction of asynchronous functionality.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The janitor module now centralises shared configuration and CREATE DATABASE SQL generation in BaseDatabaseJanitor, which is inherited by synchronous and asynchronous implementations. Both initialisation paths use the shared builder, and a changelog entry records the deduplication.

Changes

DatabaseJanitor deduplication

Layer / File(s) Summary
Shared janitor base
pytest_postgresql/janitor.py
Adds BaseDatabaseJanitor with shared instance initialisation, version parsing, and CREATE DATABASE SQL construction.
Sync and async integration
pytest_postgresql/janitor.py, newsfragments/*
Updates both initialisation paths to use the instance SQL builder and records the codebase deduplication in the changelog.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: deduplicating DatabaseJanitor logic after introducing async support.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Newsfragment Check ✅ Passed A new orphan fragment newsfragments/+55f953a1.misc.rst is present, and misc is a valid towncrier type in pyproject.toml.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch deduplicate-janitor

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
pytest_postgresql/janitor.py (1)

25-26: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consolidate is_template into BaseDatabaseJanitor.

Since this PR focuses on deduplication and as_template is already managed in BaseDatabaseJanitor, you can further reduce duplication by moving the is_template method to the base class and removing it from both subclasses.

♻️ Proposed refactor
 class BaseDatabaseJanitor:
     """Common base class for database janitors."""
+
+    def is_template(self) -> bool:
+        """Determine whether the janitor maintains template or database."""
+        return self.as_template

Then, remove is_template from both DatabaseJanitor and AsyncDatabaseJanitor:

# Remove from DatabaseJanitor:
    def is_template(self) -> bool:
        """Determine whether the DatabaseJanitor maintains template or database."""
        return self.as_template

# Remove from AsyncDatabaseJanitor:
    def is_template(self) -> bool:
        """Determine whether the AsyncDatabaseJanitor maintains template or database."""
        return self.as_template
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pytest_postgresql/janitor.py` around lines 25 - 26, Move the is_template
method into BaseDatabaseJanitor, returning the existing as_template state, and
remove the duplicate implementations from DatabaseJanitor and
AsyncDatabaseJanitor. Preserve the current method signature and behavior for
both subclasses through inheritance.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@pytest_postgresql/janitor.py`:
- Around line 25-26: Move the is_template method into BaseDatabaseJanitor,
returning the existing as_template state, and remove the duplicate
implementations from DatabaseJanitor and AsyncDatabaseJanitor. Preserve the
current method signature and behavior for both subclasses through inheritance.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e749333d-3cd4-4bd7-86d3-bd1bb4be9179

📥 Commits

Reviewing files that changed from the base of the PR and between 42ea97f and cfe8684.

📒 Files selected for processing (2)
  • newsfragments/+55f953a1.misc.rst
  • pytest_postgresql/janitor.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant