Skip to content

feat: add --ignore-schema to exclude schemas from the diff - #175

Merged
Apakottur merged 2 commits into
mainfrom
feat/ignore-schema
Jul 20, 2026
Merged

feat: add --ignore-schema to exclude schemas from the diff#175
Apakottur merged 2 commits into
mainfrom
feat/ignore-schema

Conversation

@Apakottur

Copy link
Copy Markdown
Owner

What

A new repeatable flag --ignore-schema (library param ignore_schemas: Sequence[str]) that excludes named schemas from the diff entirely — their tables and every other object, and the CREATE/DROP of the schema itself, are ignored. This includes object kinds pgmig cannot otherwise process (e.g. a rule or an invalid index in an ignored schema no longer blocks the run).

Details

Implemented at the introspection boundary, so the diff layer is untouched — ignored objects simply never exist in the model:

  • Guards (unsupported, invalid_indexes, matview_dependencies) read the ignore set from the introspection context and skip findings in ignored schemas, so an unsupported/invalid object in one does not raise.
  • introspect_db prunes the assembled DbIntrospectionResult of every ignored schema and all references to it, after the loaders run (they share queries with cross-schema dependency edges, so pruning is applied once to the finished model): schema_by_name, extensions installed into those schemas, the view / matview / view-column / composite-type / enum-column dependency maps (by key and by value), and schema-scoped default-privilege rules. Empty ignore set → no-op early return.
  • Wired through agenerate/generate and the CLI.
source target --ignore-schema ext
ext schema + its objects (empty diff)
ext schema + its objects (empty diff)
ext.t differs; public.t new only CREATE TABLE public.t
ext has a rule / invalid index no PgmigUnsupportedError

Notes

  • The value-side pruning of dependency maps matters for correctness, not just tidiness: e.g. a kept enum whose value list changes must not drag an ignored-schema column into its rewrite. (Topological ordering already tolerates stray edges, but the enum-rewrite path walks the dependency list directly.)
  • Design choice: applied as a post-introspection model prune rather than editing ~15 introspection SQL files — one contained change, and the diff generators need no awareness of the flag.
  • Verified: 11 new tests (create/drop/drift suppression, other-schemas-still-diffed, multiple schemas, all three guards, a control without the flag, plus a direct unit test of the prune covering every structure) — each migration applied and confirmed to converge. 573 tests across the API/introspect/diff/CLI suites green; mypy + ty + ruff + cspell clean; new code at 100% branch coverage. README flags table updated.

@Apakottur
Apakottur force-pushed the feat/ignore-schema branch from 6fe73be to 1d079b3 Compare July 20, 2026 10:38
@Apakottur
Apakottur changed the base branch from main to refactor/introspection-row-base July 20, 2026 10:50
Base automatically changed from refactor/introspection-row-base to main July 20, 2026 10:52
Exclude named schemas from the diff entirely: run_introspection_query
drops their rows for every LOAD query, so no create/drop of the schema
or its objects is emitted. A schema connected to a kept schema by any
dependency is refused up front (schema_connections), since ignoring a
non-isolated schema would emit a migration that fails at apply.

Filtering is driven by the query's kind: LOAD queries are filtered,
GUARD queries are not. So an unsupported object or invalid index in an
ignored schema still refuses the run -- --ignore-schema excludes objects
from the diff, it does not silence a database pgmig cannot process.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vc8vdq3jNTBHg3TfV6L7BD
@Apakottur
Apakottur force-pushed the feat/ignore-schema branch from 1d079b3 to 38b2084 Compare July 20, 2026 11:56
@Apakottur
Apakottur merged commit c8277f5 into main Jul 20, 2026
16 checks passed
@Apakottur
Apakottur deleted the feat/ignore-schema branch July 20, 2026 12:07
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