Skip to content
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

Allow full table updates again #2414

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- #2277, #2238, #1643, Prevent views from breaking one-to-many/many-to-one embeds when using column or FK as target - @steve-chavez
+ When using a column or FK as target for embedding(`/tbl?select=*,col-or-fk(*)`), only tables are now detected and views are not.
+ You can still use a column or an inferred FK on a view to embed a table(`/view?select=*,col-or-fk(*)`)
- #1959, An accidental full table PATCH(without filters) is not possible anymore, it requires filters or a `limit` parameter - @steve-chavez, @laurenceisla
- #2317, Increase the `db-pool-timeout` to 1 hour to prevent frequent high connection latency - @steve-chavez
- #2341, The search path now correctly identifies schemas with uppercase and special characters in their names (regression) - @laurenceisla
- #2364, "404 Not Found" on nested routes and "405 Method Not Allowed" errors no longer start an empty database transaction - @steve-chavez
Expand All @@ -82,8 +81,6 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- #2277, Views now are not detected when embedding using the column or FK as target (`/view?select=*,column(*)`) - @steve-chavez
+ This embedding form was easily made ambiguous whenever a new view was added.
+ For migrating, clients must be updated to the embedding form of `/view?select=*,other_view!column(*)`.
- #1959, A full table PATCH(without filters) is now restricted, it requires a `limit` parameter - @steve-chavez
+ A `PATCH /tbl` will now result in 0 rows updated, unless `PATCH /tbl?limit=10&order=<pkcol>` is done
- #2312, Using `Prefer: return=representation` no longer returns a `Location` header - @laurenceisla

## [9.0.1] - 2022-06-03
Expand Down
7 changes: 4 additions & 3 deletions src/PostgREST/Query/QueryBuilder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ mutateRequestToQuery (Update mainQi uCols body logicForest pkFlts range ordts re
SQL.sql $ "SELECT " <> emptyBodyReturnedColumns <> " FROM " <> fromQi mainQi <> " WHERE false"

| range == allRange =
let whereLogic | null logicForest = if null pkFlts then "FALSE" else pgrstUpdateBodyF
| otherwise = logicForestF in
let whereLogic | null logicForest = if null pkFlts || not colsHavePk then mempty else " WHERE " <> pgrstUpdateBodyF
steve-chavez marked this conversation as resolved.
Show resolved Hide resolved
| otherwise = " WHERE " <> logicForestF in
"WITH " <> normalizedBody body <> " " <>
"UPDATE " <> mainTbl <> " SET " <> SQL.sql nonRangeCols <> " " <>
"FROM (SELECT * FROM json_populate_recordset (null::" <> mainTbl <> " , " <> SQL.sql selectBody <> " )) pgrst_update_body " <>
"WHERE " <> whereLogic <> " " <>
whereLogic <> " " <>
SQL.sql (returningF mainQi returnings)

| otherwise =
Expand All @@ -137,6 +137,7 @@ mutateRequestToQuery (Update mainQi uCols body logicForest pkFlts range ordts re

where
mainTbl = SQL.sql (fromQi mainQi)
colsHavePk = all (`elem` uCols) pkFlts
logicForestF = intercalateSnippet " AND " (pgFmtLogicTree mainQi <$> logicForest)
pgrstUpdateBodyF = SQL.sql (BS.intercalate " AND " $ (\x -> pgFmtColumn mainQi x <> " = " <> pgFmtColumn (QualifiedIdentifier mempty "pgrst_update_body") x) <$> pkFlts)
emptyBodyReturnedColumns = if null returnings then "NULL" else BS.intercalate ", " (pgFmtColumn (QualifiedIdentifier mempty $ qiName mainQi) <$> returnings)
Expand Down
Loading