-
Notifications
You must be signed in to change notification settings - Fork 255
fix: automatically set default schema env var for type generation #3243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
fix: automatically set default schema env var for type generation #3243
Conversation
Pull Request Test Coverage Report for Build 15540005669Details
💛 - Coveralls |
var defaultSchemaEnv string | ||
if len(schemas) == 1 && schemas[0] != "public" { | ||
defaultSchemaEnv = schemas[0] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a new flag so it doesn't break existing users that rely on the generated default schema. For eg. supabase gen types --schema private --set-default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sweatybridge Thanks. I've implemented a set-default
flag for backwards compatibility that makes the behavior now explicit and opt-in. The new behavior is now:
supabase gen types --schema private --set-default
I've added 4 tests as well to test the core feature, backward compatibility and edge cases. |
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