Skip to content

drizzle-kit: load pg enums referenced from filtered schemas#5811

Open
youcefzemmar wants to merge 1 commit into
drizzle-team:mainfrom
youcefzemmar:fix/bug-set-storage-plain-on-postgres-causes-unknown-d
Open

drizzle-kit: load pg enums referenced from filtered schemas#5811
youcefzemmar wants to merge 1 commit into
drizzle-team:mainfrom
youcefzemmar:fix/bug-set-storage-plain-on-postgres-causes-unknown-d

Conversation

@youcefzemmar
Copy link
Copy Markdown

What

Broadens the pg_enum introspection query in pgSerializer.fromDatabase so it also returns enums referenced by columns in any table/view/materialized view inside schemaFilters, 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_type is declared in public, but auth.oidc_providers.auth_type references it. With schemaFilter: ['auth'], the enums query filters by n.nspname = 'auth', so the enum is never loaded. The column then falls back to:

auth_type: unknown("auth_type")
// TODO: failed to parse database type 'provider_auth_type'

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

  • added introspect enum referenced from non-filtered schema in drizzle-kit/tests/introspect/pg.test.ts — declares my_enum in public, a providers table in schema2 using it, runs introspectPgToFile with ['schema2'], asserts no diff statements
  • ran the new test plus all existing enum tests in that file: green
  • ran the full tests/introspect/pg.test.ts suite: 35 passed, 1 todo
  • pnpm tsc clean

Notes

  • The OR-branch widens enums loaded → these enums now appear as export const ... = pgEnum(...) declarations in the generated schema file. That's the intended outcome; the column wouldn't otherwise resolve.
  • Scoped to enums — domain types are out of scope. Confirmed via niledatabase/niledatabase source that provider_auth_type is an enum.
  • cls.relkind IN ('r','v','m') matches getColumnsInfoQuery so we only pull enums referenced by columns we actually introspect.

Fixes #5801.

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.
@youcefzemmar youcefzemmar marked this pull request as ready for review May 27, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: SET STORAGE PLAIN on postgres causes unknown data type in introspection

1 participant