Repository navigation
feat(postgrest): query a table in the schema its model declares - #1030
Merged
Merged
Conversation
…e-schema # Conflicts: # packages/Postgrest/Postgrest/ClientOptions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
A model can name the schema its table lives in,
[Table("stock", Schema = "inventory")], and every request on that table targets it, so tables from several schemas work side by side on one client. This is groundwork for generated types (database.generated_types.typed_queries), whose tables carry their schema; it carries no capability annotation.Public API
Behavior
The schema of a table is resolved once, when the table is built, in this order:
WithSchema(...);TableAttribute.Schema, when it is neither null nor empty;ClientOptions.Schema.A deliberate per-client scope wins over the table's home, so one table shape can be queried in several schemas (archive, schema per tenant); the table's home wins over the client-wide default, including a
ClientOptions.Schemaset at construction. This is the rule supabase-flutter applies to its table definitions (_schemaIsExplicit ? _schema : (table.schema ?? _schema)).It reaches every request on the table through the usual profile header (
Accept-Profilefor GET and HEAD,Content-Profileotherwise): reads,Count,GetAsync<TResult>projections and writes, andTableWithCacheandSupabaseTable, which build onTable. A model read through the table carries the same options, so itsUpdate/Deletetarget the same schema.A table with a schema of its own works on a copy of the client's options; the client's options are unchanged.
WithSchemamarks the options it derives as scoped, and the mark survives further derivations such asWithAccessToken.Embedding across schemas is not possible in PostgREST: relationships are resolved within the schema of the request (
PGRST200), so the schema of an embedded model is not used.Failures are unchanged: a schema the API does not expose answers 406
PGRST106(FailureHint.Reason.InvalidSchema).Deviations from supabase-js
supabase-js has no per-table schema; a schema is chosen per client or with
.schema(). The precedence above matches supabase-flutter.Tests
TableSchemaTestspersonal.usersinserts, reads and updates there from apublicclient, and aWithSchema("public")client readspublic.usersinsteadTableSchemaRequestTestsThe tests failed before the change (8 of 15: every request targeted
public).Diff coverage: 100% (14 lines). Mutation: 8 killed of 8 tested on changed lines, 0 survivors.
Notes
RequestApprovalFixtureanswers withContent-Range: */0, so a count can be pinned through it.TableAttribute.csmoved to a file-scoped namespace with its docs completed, as the format gate requires of a changed file.TableWithCacheis kept per schema in its own fix (fix(postgrest): keep the cache of a table separate per schema #1029). The Realtime subscription ofSupabaseTablestill usespublic; it follows in its own PR with a publicIPostgrestTable.Schema.