Skip to content

feat(postgrest): target another schema from a derived client - #1022

Merged
Tr00d merged 1 commit into
masterfrom
feat/database.query.schema_selection
Dec 2, 2026
Merged

Tr00d merged 1 commit into
masterfrom
feat/database.query.schema_selection

Conversation

@Tr00d

@Tr00d Tr00d commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Summary

A caller can derive a Postgrest client that targets another exposed schema for its table queries and function calls. The client it came from is unchanged.

Capability: database.query.schema_selection, Schema Selection. This changes the status from partially implemented to implemented. There is no capability spec for it.

Public API

// IPostgrestClient (Supabase.Postgrest), implemented by Client
IPostgrestClient WithSchema(string schema);

// FailureHint.Reason (Supabase.Postgrest.Exceptions), new member at the end
InvalidSchema
var personal = client.WithSchema("personal");
var users = await personal.Table<User>().Get();
var status = await personal.Rpc<string>("get_status", new { name_param = "leroyjenkins" });

// umbrella client
var rows = await supabase.Postgrest.WithSchema("personal").Table<User>().Get();

Behavior

  • Operations: no new endpoint. Every request from the derived client carries the schema: table reads, writes and counts, CallFunction, Rpc, and the Update and Delete of models it returns or attaches. GET sends it as Accept-Profile. POST, PATCH, PUT and DELETE send it as Content-Profile (Switching schemas).
  • Inputs: the schema name is sent as given, with no checks. A null name throws ArgumentNullException before any request.
  • What the derived client keeps:
    • the base URL;
    • a copy of every option (headers, query parameters, access-token callback, retry, timeout, logger, clock, HttpClient and proxy, enum serialization);
    • the GetHeaders callback of the client it came from, so the umbrella client's apikey and session token keep reaching it.
  • Outputs: a new IPostgrestClient. The two clients' options, including the Headers and QueryParams dictionaries, are separate copies, and each keeps its comparer. No HttpClient is created: the derived client sends through the same one.
  • Failures: a schema the API does not expose gets 406 with PGRST106. That becomes a PostgrestException with Reason = FailureHint.Reason.InvalidSchema. All other failures are unchanged.
  • State: none.

Deviations from supabase-js

  • Named WithSchema, the .NET name for a derived copy, where supabase-js uses schema().
  • No compile-time schema typing, since this SDK has no generated database types.
  • The umbrella ISupabaseClient gets no shortcut. supabase.Postgrest.WithSchema(...) reaches the same client.

Tests

Tier Class Pins
E2E WithSchemaTests rows and a function of personal are read through the derived client; the original client still reads public; an unexposed schema throws InvalidSchema
Contract WithSchemaRequestTests Accept-Profile on a read, Content-Profile on Rpc; the original client keeps its schema and headers; the GetHeaders callback is carried over; PGRST106 maps to InvalidSchema
Unit WithSchemaOptionsTests every other option and the base URL are kept; the header and query-parameter comparers are kept; a null schema throws

Diff coverage: 100% (9 lines). Mutation: 3/3 killed on changed lines, 0 survivors. Stryker generates no mutant for the ?? throw guard, the target-typed object initializer or the dictionary copies; the tests cover them.

Notes

  • ExplainRequestTests.ExplainAsync_ShouldNotReportMediaTypeNotAcceptable_GivenAnotherNotAcceptableAnswer used a PGRST106 body as its example of an unrelated 406. That body now maps to InvalidSchema, so the test uses a 406 that carries no PostgREST code.
  • An empty schema name goes through unchecked. Because of the existing rule in PrepareRequestHeaders, an empty schema sends no profile header, so the request goes to the server's default schema; PostgREST is never asked about the empty name. This is the same as ClientOptions.Schema = "" today.
  • Count() sends Content-Profile on HEAD, so it counts the default schema. This affects the derived client and ClientOptions.Schema alike. fix(postgrest): count rows in the configured schema #1021 fixes it.
  • Follow-up for v9: ClientOptions.Schema defaults to "public", which copies the service's default.

@Tr00d
Tr00d marked this pull request as ready for review December 2, 2026 07:32
@Tr00d
Tr00d merged commit 39bcf46 into master Dec 2, 2026
11 checks passed
@Tr00d
Tr00d deleted the feat/database.query.schema_selection branch December 2, 2026 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant