You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add constraints section to .pgschemaignore (#429, #447) (#452)
* feat: add constraints section to .pgschemaignore (#429, #447)
Adds a new [constraints] section to .pgschemaignore that matches table
constraints by name (glob). Ignored constraints are filtered at the
inspector, so they are excluded from dump, plan generation, and drift
detection alike — pgschema neither creates, drops, nor reports them.
Use cases:
- Out-of-band constraints, e.g. disabled during an AWS DMS migration and
re-added manually afterward, that plan should not flag for drop (#447).
- Cross-schema foreign keys: ignore them to bootstrap each schema
independently, then drop the ignore once all tables exist (#429).
Mirrors the existing per-object pattern (Indexes, #441): Constraints
[]string on IgnoreConfig with ShouldIgnoreConstraint(name), a
ConstraintIgnoreConfig struct on TomlConfig, and a filter in the
inspector's constraint attach loop.
Fixes#447
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* perf: skip ignored constraints before per-column position queries
Move the ShouldIgnoreConstraint check into the initial constraint loop,
before getConstraintColumnPosition runs per column, so ignored
constraints no longer incur N+1 DB queries that are immediately
discarded. The attach-time check is removed since ignored constraints
now never enter constraintGroups.
Addresses Copilot review feedback on #452.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/cli/ignore.mdx
+24Lines changed: 24 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,6 +41,12 @@ patterns = ["type_test_*"]
41
41
[sequences]
42
42
patterns = ["seq_temp_*", "seq_debug_*"]
43
43
44
+
[indexes]
45
+
patterns = ["idx_temp_*", "manual_*"]
46
+
47
+
[constraints]
48
+
patterns = ["fk_legacy_*"]
49
+
44
50
[privileges]
45
51
patterns = ["deploy_bot", "admin_*"]
46
52
@@ -104,6 +110,24 @@ patterns = ["deploy_bot"] # Ignore ALTER DEFAULT PRIVILEGES for deploy_bot
104
110
105
111
The `[privileges]` section filters explicit grants (`GRANT ... TO role`), including column-level privileges. The `[default_privileges]` section filters `ALTER DEFAULT PRIVILEGES` statements.
106
112
113
+
## Constraints
114
+
115
+
The `[constraints]` section matches table constraints by **constraint name** (primary keys, unique, foreign keys, check, and exclusion constraints). When a constraint is ignored, pgschema neither creates, drops, nor reports drift on it — it is left entirely to be managed out-of-band.
116
+
117
+
```toml
118
+
[constraints]
119
+
patterns = ["fk_*", "!fk_core_*"]
120
+
```
121
+
122
+
This is useful when:
123
+
124
+
1.**Out-of-band constraints** - A constraint is added and managed manually (e.g. disabled during an AWS DMS migration and re-added afterward), and you don't want `pgschema plan` to flag it for drop.
125
+
2.**Cross-schema foreign keys** - When modules live in separate schemas with foreign keys between them, ignore the cross-schema foreign keys so each schema can be bootstrapped independently, then drop the ignore to let pgschema manage them once all tables exist.
126
+
127
+
<Warning>
128
+
Patterns match the constraint name only, which is not necessarily unique across tables. Be careful with broad patterns like `*`, as ignoring a primary key or unique constraint can leave a table without the keys it needs.
129
+
</Warning>
130
+
107
131
## Triggers on Ignored Tables
108
132
109
133
Triggers can be defined on ignored tables. The table structure is not managed, but the trigger itself is.
0 commit comments