drizzle-kit: load pg enums referenced from filtered schemas#5811
Open
youcefzemmar wants to merge 1 commit into
Open
drizzle-kit: load pg enums referenced from filtered schemas#5811youcefzemmar wants to merge 1 commit into
youcefzemmar wants to merge 1 commit into
Conversation
The introspection `pg_enum` query filters by `schemaFilters`, so an
enum declared in a schema that's not in the filter (e.g. `public`) but
referenced by a column in a schema that is (e.g. Nile's `auth`) was
never loaded. The column type then fell back to
`unknown("...") // TODO: failed to parse database type`.
Broaden the query to also include enums whose oid is referenced by a
column of a table/view/materialized view inside the filtered schemas,
preserving the empty-filter fall-through.
Fixes drizzle-team#5801.
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
Broadens the
pg_enumintrospection query inpgSerializer.fromDatabaseso it also returns enums referenced by columns in any table/view/materialized view insideschemaFilters, not only enums declared in those schemas.Why
The reported "SET STORAGE PLAIN" symptom in #5801 is incidental — the real bug is cross-schema enum references on Nile (and any setup that hides
public).public.provider_auth_typeis declared inpublic, butauth.oidc_providers.auth_typereferences it. WithschemaFilter: ['auth'], the enums query filters byn.nspname = 'auth', so the enum is never loaded. The column then falls back to:Pulling enums in by oid-reference fixes the introspection without changing what gets loaded when the enum's own schema is already in the filter. Empty-filter fall-through is preserved.
Testing
introspect enum referenced from non-filtered schemaindrizzle-kit/tests/introspect/pg.test.ts— declaresmy_enuminpublic, aproviderstable inschema2using it, runsintrospectPgToFilewith['schema2'], asserts no diff statementstests/introspect/pg.test.tssuite: 35 passed, 1 todopnpm tsccleanNotes
export const ... = pgEnum(...)declarations in the generated schema file. That's the intended outcome; the column wouldn't otherwise resolve.niledatabase/niledatabasesource thatprovider_auth_typeis an enum.cls.relkind IN ('r','v','m')matchesgetColumnsInfoQueryso we only pull enums referenced by columns we actually introspect.Fixes #5801.