refactor(pipeline): share psycopg scaffolding between checkpoint and audit#241
Merged
miguelgfierro merged 1 commit intoMay 28, 2026
Conversation
…audit Extract the duplicated Postgres setup (optional-dep guard, dsn-xor-connection check, table-name validation, lazy idempotent DDL) into a single PsycopgBackend base class in pipeline/_psycopg_backend.py. PostgresCheckpointer and PostgresAuditLog now inherit from it; each only declares its DDL and default table name. Tests updated to monkeypatch _psycopg on the shared module.
ancongui
pushed a commit
that referenced
this pull request
May 31, 2026
…-helper refactor(pipeline): share psycopg scaffolding between checkpoint and audit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses finding #6 from the simplifier review of #232.
PostgresCheckpointerandPostgresAuditLoghad four pieces of identical boilerplate copy-pasted betweencheckpoint.pyandaudit.py:try: import psycopg as _psycopgoptional-dep guard.if _psycopg is None: raise ImportError(...)with the same install hint.(dsn is None) == (connection is None)xor-check.table_name.replace(\"_\", \"\").isalnum()validator (interpolated into DDL)._ddl_appliedflag +_ensure_tablelazy-DDL method.This PR extracts them into a single
PsycopgBackendbase class in a newpipeline/_psycopg_backend.pymodule. Each concrete backend now only declares its_DDLand default table name:Behavior
Unchanged. Same public API, same constructor signatures, same ImportError / ValueError messages (parametrized by
kind).Tests
The two test files used to monkeypatch
audit_module._psycopgandcheckpoint_module._psycopgto stub the optional dep. They now monkeypatch_psycopg_backend._psycopg(single source of truth). Same number of tests, same coverage.Verification
pytest tests/unit/pipeline/→ 142 passed.ruff check+ruff format --checkclean.Diff stats
Net is mildly positive raw LOC, but the duplication is gone — single source of truth for the Postgres scaffolding, which is what the finding called out. Future Postgres-backed backends (if any) inherit the same surface for free.