-
-
Notifications
You must be signed in to change notification settings - Fork 137
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
fix(template): dynamically set default schema alias in typescript type generation #904
fix(template): dynamically set default schema alias in typescript type generation #904
Conversation
Thanks @bug-author! Left some comments |
@soedirgo Thank you for the review. I have made the suggested changes:
Thanks for helping me refine the implementation. |
- Remove separate aliases (PublicSchema, DefaultSchemaOrPublic) from TypeScript template - Add a single DefaultSchema alias - Update all helper types (Tables, TableInsert, etc) to use DefaultSchema
607da9d
to
7cf3c78
Compare
Pull Request Test Coverage Report for Build 13716318077Details
💛 - Coveralls |
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.
Thanks again @bug-author!
Hi @soedirgo I appreciate you taking the time to refine the code, I’ll make sure to pay even closer attention to code quality in future contributions. 🫡 Thanks again! |
What kind of change does this PR introduce?
This PR fixes the incorrect default alias generation for TypeScript type schemas when using a single non‑public schema with
supabase gen types
.What is the current behavior?
Currently, the TypeScript template always hardcodes the default schema alias as:
This means that when a user generates types using a non‑public schema (for example,
--schema robo
), the generated helper types (for example.Tables<"test_table">
) incorrectly reference the public schema, even if no tables exist there.Relevant issues:
supabase gen types
#833 (for additional context)What is the new behavior?
This PR updates the TypeScript template in pg‑meta so that when exactly one non‑public schema is provided, the template automatically uses the environment variable
PG_META_GENERATE_TYPES_DEFAULT_SCHEMA
to generate a default alias. For example, if the schema provided is "robo", the template will now output:The helper types (
Tables
,TablesInsert
, etc.) referenceDefaultSchemaOrPublic
instead of the hardcoded "public". In multi‑schema scenarios, the environment variable is not set, and the default behavior (using "public") remains, the users can explicitly specify the schema for non-public tables.This change ensures:
Tables<"test_table">
) correctly resolve toDatabase["robo"]["Tables"]["test_table"]
.Tables<{ schema: "robo" }, "test_table">
).Additional context
Usage example
Corresponding cli PR