fix: automatically set default schema env var for type generation #3243
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 kind of change does this PR introduce?
This PR lets the CLI automatically detect when exactly one non‑public schema is provided and sets the environment variable
PG_META_GENERATE_TYPES_DEFAULT_SCHEMA
accordingly.What is the current behavior?
Currently, when running
supabase gen types
, the CLI passes the schema flags directly topostgres‑meta
without automatically setting a default schema. This results in the generated TypeScript file always defaulting to the "public" alias:Even if a non‑public schema is specified (for example,
--schema robo
), helper types (likeTables<"test_table">
) incorrectly reference the public schema.Relevant issues:
#3061
#3146
What is the new behavior?
The CLI now automatically checks if exactly one schema is provided (and if that schema is not "public"). If so, it sets the environment variable
PG_META_GENERATE_TYPES_DEFAULT_SCHEMA
to that schema's name. This allowspostgres‑meta
to generate a default alias based on the provided schema (for example, for "robo", the generated file will include):In single‑schema mode, shorthand type references (like
Tables<"test_table">
) correctly resolve to the non‑public schema. In multi‑schema scenarios, the variable is not set, and users must explicitly specify the schema for non‑public tables.Additional context
Corresponding postgres-meta PR