Repository navigation
fix!: make order() default to ascending - #1658
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (8)
🚧 Files skipped from review as they are similar to previous changes (6)
📝 WalkthroughWalkthroughThe PostgREST and Supabase stream ChangesAscending order defaults
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
fc1afc6 to
b99c800
Compare
`PostgrestTransformBuilder.order()` and `SupabaseStreamBuilder.order()`
defaulted `ascending` to `false`, so `.order('created_at')` returned rows in
descending order. That was inherited from the pre-TypeScript postgrest-js in
2020 and never revisited after postgrest-js moved to `ascending = true`, which
left Dart disagreeing with both SQL's `ORDER BY` and every other client
library.
Both defaults are now `true`. Callers that want descending order pass
`ascending: false` explicitly.
Tests that were exercising the old implicit default now request descending
explicitly, and the new default is covered by an offline query parameter test,
a postgrest integration test and a stream test.
`MIGRATION.md` gets a v2 to v3 section for it, since the change is silent and
needs checking at every call site rather than being caught by the analyzer.
BREAKING CHANGE: `order()` now sorts ascending when `ascending` is omitted, in
both postgrest and the supabase stream builder. Calls that relied on the old
default silently reverse their result order and have to pass
`ascending: false`.
b99c800 to
ed13a52
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
Closes #1638
What kind of change does this PR introduce?
Breaking change.
What is the current behavior?
order()defaultsascendingtofalsein two places, so omitting the parameter sorts descending:PostgrestTransformBuilder.order()SupabaseStreamBuilder.order().order('created_at')therefore returns newest rows first, which disagrees with SQL'sORDER BY(defaults toASC) and withpostgrest-js({ ascending = true }). The failure is silent: the query succeeds, the row count and types are right, only the order is wrong.The default was never chosen for Dart.
postgrest-dart7a8f8b7(2020-09-10) ported the firstorder()from the pre-TypeScriptpostgrest-js, which then hadorder(columnName, ascending = false, nullsFirst = false).postgrest-js2960d09moved to{ ascending = true }ten days later and Dart never followed. #1637 documented the current behavior in the meantime.Two examples in this repository were already wrong because of it, which is the clearest evidence that the default surprises people:
examples/realtime_room/lib/room_repository.dartsays "SELECT the existing messages once, oldest first" and returned them newest first.examples/database_crud/lib/tasks_repository.dartsays "ordered alphabetically by name" and returned projects in reverse alphabetical order.Both are now correct without touching their query code.
What is the new behavior?
PostgrestTransformBuilder.order():bool ascending = true.SupabaseStreamBuilder.order():bool ascending = true, so.stream()and.select()agree on what an unqualified.order()means.postgrest-js, since there is no longer a divergence.nullsFirstis unchanged atfalse. That already matchedpostgrest-jsand PostgREST.Migration
MIGRATION.mdgets anorder() now sorts ascending by defaultsection under v2 to v3, covering both call sites, why the analyzer will not catch it, and how to keep the old behavior:The section also points out that
ascending: falsealready means descending on v2, so consumers can add it before upgrading and leave this change out of the upgrade itself.Tests
packages/postgrest/test/order_default_test.dartasserts the generatedorderquery parameter without a backend: the default, explicitascending: false,nullsFirst: true, a referenced table, and that chainedorder()calls keep their own direction.transforms_test.dartgainsorder defaults to ascendingandorder descendingagainst the local stack.mock_test.dartgainsorder defaults to ascendingfor the stream builder, and the mock server now answersorder=id.asc.nullslast.ascending: falseexplicitly, so their coverage of descending order is preserved rather than silently reinterpreted.melos analyzeandmelos formatare clean.packages/postgrest(196 tests) andpackages/supabase(136 tests) pass in full against a local Supabase stack.Additional context
Part of the v3 umbrella (#1278).
Summary by CodeRabbit
New Features
ascending: false.Documentation
Tests