Add support for indexes section in .pgschemaignore#441
Merged
Conversation
Adds a new [indexes] section to .pgschemaignore that lets users preserve indexes which exist in the database but are not declared in their .sql files. Without this, manually-added indexes (e.g. perf hotfixes) are flagged for drop by `pgschema plan`. Mirrors the existing per-object pattern: `Indexes []string` on `IgnoreConfig` with `ShouldIgnoreIndex(name)`, an `IndexIgnoreConfig` struct on `TomlConfig`, and a filter in `Inspector.buildIndexes` that skips ignored index names before they enter the IR. Fixes pgplex#406 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Greptile SummaryThis PR adds ignore support for database indexes. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Reviews (1): Last reviewed commit: "Add support for indexes section in .pgsc..." | Re-trigger Greptile |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends pgschema’s ignore configuration so users can exempt specific indexes from inspection/diffing, preventing pgschema plan from proposing drops for operationally-created indexes that aren’t declared in desired-state SQL.
Changes:
- Added
[indexes]support to.pgschemaignoreviaIgnoreConfig.Indexes+ShouldIgnoreIndex. - Updated ignore-file TOML loader to parse the new indexes section into
ir.IgnoreConfig. - Updated inspector index discovery to skip ignored index names, and added unit + integration coverage for the #406 scenario.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
ir/inspector.go |
Skips indexes during inspection when they match ignore patterns, keeping them out of IR/dump/plan. |
ir/ignore.go |
Adds Indexes patterns and ShouldIgnoreIndex helper to mirror existing ignore APIs. |
ir/ignore_test.go |
Extends ignore unit tests to cover indexes and nil-config behavior. |
cmd/util/ignoreloader.go |
Extends .pgschemaignore TOML structure parsing to include [indexes] patterns = [...]. |
cmd/util/ignoreloader_test.go |
Verifies the loader round-trips the new [indexes] section into IgnoreConfig.Indexes. |
cmd/ignore_integration_test.go |
Adds an integration test reproducing #406 to ensure ignored live-only indexes don’t appear in dump/plan. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tianzhou
approved these changes
May 30, 2026
Contributor
tianzhou
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the contribution.
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.
Summary
[indexes]section to.pgschemaignoreso users can keep indexes that exist in the live database but are not declared in their schema.sqlfiles. Without this, manually-added indexes (perf hotfixes, ad-hoc operational fixes) are flagged for drop bypgschema plan.IgnoreConfig.Indexes+ShouldIgnoreIndex(name)mirror the existing per-object pattern.Inspector.buildIndexesskips ignored index names before they enter the IR, so they don't appear indumpand don't show up as drift inplan.Fixes #406
Test plan
TestIgnoreIndexes(incmd/ignore_integration_test.go) reproducing the exact Add support for indexes to .pgschemaignore #406 scenario: amanual_perf_idxexists on a managed table, the desired schema doesn't declare it, the ignore config listsmanual_*. Asserts the dump excludes it and the plan does not reference it.TestIgnoreConfig_AllObjectTypesandTestIgnoreConfig_NilConfigto cover indexes.TestLoadIgnoreFileFromPath_ValidTOMLto round-trip the new[indexes]section.go test ./...— ~7 min).Run just the new test:
🤖 Generated with Claude Code
Note (2026-05-23): pgproj (a downstream DACFX-shaped fork at https://github.com/guillaume86/pgproj) has adopted a hard-fork posture and will continue independently. This contribution remains open without expectation of merge; happy to address review feedback if a maintainer engages.