-
-
Notifications
You must be signed in to change notification settings - Fork 129
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(typegen): Fix support for custom SQL schemas in TypeScript type generation. #717
Conversation
test/server/typegen.ts
Outdated
PublicTableNameOrOptions extends | ||
| keyof (Database["public"]["Tables"] & Database["public"]["Views"]) | ||
| keyof (Database[keyof Database]["Tables"] & | ||
Database[keyof Database]["Views"]) |
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.
Hmm I think the concept here is to constrain each table to a new type on its own, for eg. PublicTableNameOrOptions
type corresponds to the public
schema exclusively.
We might need to generate separate export type Tables
blocks depending on the schema name. @soedirgo wdyt?
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.
Ah sounds good! I was looking at that approach but since I don't personally use the new Table types I didn't know what the context of including them was. Happy to make this change (mapping over each schema to create the PascalCase Table types, and updating the typegen tests) and push up later this evening.
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 @soedirgo just pushed up some changes in order to create schema-specific types for Tables, TablesInsert, TablesUpdate, and Enums. Would love feedback on the source and test cases (should I add an additional test case to cover schemas not named public, and having multiple schemas)?
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.
After some thought, I think there's a backwards compatibility issue with this change. So I proposed a new approach in #723 and added you as the co-author.
We can close this PR if you are happy with it.
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.
This looks good to me. Will wait for @soedirgo's confirmation.
@sweatybridge mentioned in #723 I'm happy with those changes - I'll close this PR now. Thanks! |
What kind of change does this PR introduce?
[x] Patches PR #654 to support SQL schemas outside of "public". Cannot directly use keyword "schema" due to circular type constraint error in definition
PublicTableNameOrOptions
.[x] Update type generation tests to reflect updated TypeScript types, with local run of
npm run test
confirming 96 tests passed.Addresses GitHub issue #716.
What is the current behavior?
When running:
Against a Supabase instance where database is at
postgresql://postgres:[email protected]:54322/postgres
and has schemaopenai
among others, typesTable
,TablesInsert
,TablesUpdate
, andEnums
result in type errors because schemapublic
is not defined.What is the new behavior?
Against a Supabase instance where database is at
postgresql://postgres:[email protected]:54322/postgres
and has schemaopenai
among others, typesTable
,TablesInsert
,TablesUpdate
, andEnums
do not result in type errors.Additional context
N/A.