Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions docs/cli/dump.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,12 @@ prefix distinguishes multiple constraints on the same table. The exporter keeps
these files in dependency order in `schema.sql`, after the required tables.
Load files in the generated include order to preserve these dependencies.

For partitioned indexes, `pgschema` creates the tables and leaf indexes first.
The exporter then creates each parent index with `ON ONLY` and attaches its
recorded child indexes with `ALTER INDEX ... ATTACH PARTITION`. This preserves
custom child names and leaves intentionally unattached indexes separate.
If a child index backs a `UNIQUE` or `PRIMARY KEY` constraint, the constraint
generator creates that index. The exporter then attaches it to its recorded
parent index.
Multi-file dumps put parent indexes and their attachments under `indexes/`,
for example `indexes/0001_events_lookup.sql`, after the table includes.
For partitioned indexes, `pgschema` creates the tables and leaf indexes first,
then each parent index with `ON ONLY`, then attaches the children with
`ALTER INDEX ... ATTACH PARTITION`. This keeps custom child index names and
leaves unattached indexes unattached. Multi-file dumps write parent indexes and
their attachments under `indexes/`, such as `indexes/0001_events_lookup.sql`,
after the table includes.

Each individual file (e.g., `tables/users.sql`) contains the specific object definition:
```sql
Expand Down
26 changes: 8 additions & 18 deletions docs/cli/ignore.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -121,24 +121,14 @@ The `[privileges]` section filters explicit grants (`GRANT ... TO role`), includ

## Partitioned indexes

When `dump` retains a partitioned index, it must also retain that index's attached
children. If the inspector excludes an attached child because of an index, table,
or owning constraint ignore pattern, `dump` returns an error naming the parent and child before writing
any output. Existing output files remain unchanged. `dump` performs the same check
for nested partitions.

For example, `event_unique` has an attached child named `early_custom_unique`.
If `early_custom_unique` is ignored while `event_unique` is retained, `dump` returns
an error.
Remove the conflicting ignore pattern or add a negation pattern to retain the
child index and its table. Ignoring an unattached index remains supported.

For constraint-backed child indexes, use `[constraints]` to ignore the owning
constraint. An `[indexes]` pattern does not exclude a constraint-backed index.
For example, if `early_custom_unique` is a `UNIQUE` constraint, excluding it under
`[constraints]` while retaining its parent index causes `dump` to reject the dump.

`plan` and `apply` retain their existing ignore behavior.
A retained partitioned index must keep all of its attached child indexes. If a
pattern ignores an attached child (by index, table, or owning constraint) while
its parent is retained, `dump` fails before writing any output. Remove the
pattern or add a negation pattern to keep the child. Ignoring an unattached
index is fine.

`[indexes]` patterns do not match constraint-backed indexes; use `[constraints]`
to ignore those.

## Constraints

Expand Down
21 changes: 8 additions & 13 deletions docs/cli/plan.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,16 @@ By default, pgschema uses an embedded PostgreSQL instance to validate your desir

## Creating partitioned indexes

When `plan` creates an entirely new managed partition hierarchy and all recorded
table and index dependencies are present, it preserves standalone index names and
attachments. It creates the tables and leaf indexes first, then parent indexes
with `ON ONLY`, explicit attachments, and dependent foreign keys.

For example, creating new `events` tables preserves the attachment of a named
child index `early_custom_lookup` to `event_lookup`. An equivalent unattached index
stays unattached. The same creation order applies when unrelated tables already
exist in the target schema.

For hierarchies containing existing tables, unmanaged ancestors, or excluded
dependencies, migration generation retains recursive index creation. This does
not reconcile index attachments on existing tables. Constraint-backed indexes
When `plan` creates a partition hierarchy from scratch, it keeps standalone index
names and attachments from the desired state: tables and leaf indexes first,
then parent indexes with `ON ONLY`, then the attachments and any dependent
foreign keys. An unattached index stays unattached. Constraint-backed indexes
remain under constraint management.

When part of the hierarchy already exists in the target, or part of it is
ignored, `plan` falls back to recursive index creation and does not reconcile
attachments on existing tables.

## Basic Usage

```bash
Expand Down