[Pg-kit] Ignore leaf partitions when introspecting Postgres - #6196
Open
EndiButler wants to merge 1 commit into
Open
[Pg-kit] Ignore leaf partitions when introspecting Postgres#6196EndiButler wants to merge 1 commit into
EndiButler wants to merge 1 commit into
Conversation
A leaf partition has relkind = 'r', so introspection returned it as an ordinary table. pull then duplicated the parent's columns and indexes for every partition, and push proposed DROP TABLE for each partition the schema file did not declare - then aborted mid-migration, because dropping the parent had already dropped them: DROP TABLE "logs"; DROP TABLE "logs_2026_01"; -- ERROR: table "logs_2026_01" does not exist Filtering on relispartition keeps the partitioned parent and hides its partitions, which also removes their auto-created indexes from every downstream introspection query. Refs drizzle-team#2854
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.
What this fixes
A leaf partition has
relkind = 'r', so Postgres introspection returns it as an ordinary table. Nothing downstream knows it is a partition.Reproduced on this branch's parent (
beta,drizzle-kit@1.0.0-rc.4) with one partitioned parent and three monthly partitions, against a schema file that does not declare them:Two separate problems:
pushproposes dropping partitions the user never declared — for the common time-range retention setup, those are created bypg_partmanor a cron job and hold the data the partitioning exists to protect.table "logs_2026_01" does not exist, leaving the database partially migrated.pullis affected the same way — it emits aCREATE TABLEper partition, duplicating the parent's columns and its automatically propagated indexes.This is what was reported in #2854 ("
drizzle-kit pushseems to be blowing up").The fix
Filter on
relispartitionin both Postgres introspection paths (introspect.tsandaws-introspect.ts). The partitioned parent stays; its partitions are hidden. Because the child OIDs then drop out of every downstream constraint and index query, their auto-created indexes disappear from the pulled schema too.Scope
Deliberately narrow: this is only the bug. It does not add any way to declare partitioning — that is the feature request in #2854, which I have written up separately as a design proposal with a working prototype branch. This fix stands on its own and does not depend on it.
Tests
tests/postgres/pull.test.ts— the existingintrospect partitioned tablestest now creates a real leaf partition and asserts only the parent is returned.tests/postgres/pg-tables.test.ts— newpush does not drop leaf partitions it does not know about: creates partitions outside drizzle, then assertspushproduces no statements and both partitions survive.Regression check on this machine:
tests/postgresreports the same failure set as the untouchedbetabranch (those failures need a live Postgres/PostGIS container and a builtdrizzle-orm/dist), with one additional passing test.tsc --noEmitclean for both changed files.