Repository navigation
fix(postgrest): count rows in the configured schema - #1021
Merged
Merged
Conversation
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
Count()now counts rows in the schema set byClientOptions.Schema. Before this fix it always counted the server's default schema whenever another schema was configured.This is a behavior change. A count on a client configured for a non-default schema now returns that schema's count. Before, it returned the count of the same-named table in the default schema, or failed when the default schema had no such table.
What was wrong
Count()is sent asHEAD.Helpers.PrepareRequestHeaderssentAccept-Profileonly forGETand sentContent-Profilefor every other method,HEADincluded. PostgREST reads the schema of aGETorHEADrequest fromAccept-Profile(Switching schemas), so it ignored the header and used the default schema.Confirmed on the local stack (
personalis exposed insupabase/config.toml):Content-ProfileHEAD /userswithAccept-Profile: personalpersonalHEAD /userswithContent-Profile: personal(the old behavior)publicleroyjenkinsexists only inpersonal.users. WithSchema = "personal",Countfiltered on that name returned 0 before this fix and returns 1 after it.Behavior
GETandHEADsend the configured schema asAccept-Profile.POST,PATCH,PUTandDELETEsend it asContent-Profile, as before.Tests
SchemaTestsCountwithSchema = "personal"counts the row that exists only inpersonalSchemaProfileTestsAccept-Profileand sends noContent-ProfileDiff coverage: 100% (2 lines). Mutation: 8/8 killed on changed lines, 0 survivors.