Fix unique foreign key in view (#1395)
This commit is contained in:
@@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- #1301, Fix self join resource embedding on PATCH - @herulume, @steve-chavez
|
- #1301, Fix self join resource embedding on PATCH - @herulume, @steve-chavez
|
||||||
- #1389, Fix many to many resource embedding on RPC/PATCH - @steve-chavez
|
- #1389, Fix many to many resource embedding on RPC/PATCH - @steve-chavez
|
||||||
- #1355, Allow PATCH/DELETE without `return=minimal` on tables with no select privileges - @steve-chavez
|
- #1355, Allow PATCH/DELETE without `return=minimal` on tables with no select privileges - @steve-chavez
|
||||||
|
- #1361, Fix embedding a VIEW when its source foreign key is UNIQUE - @bwbroersma
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|||||||
@@ -393,7 +393,7 @@ allColumns tabs =
|
|||||||
array_to_string(enum_info.vals, ',') AS enum
|
array_to_string(enum_info.vals, ',') AS enum
|
||||||
FROM (
|
FROM (
|
||||||
/*
|
/*
|
||||||
-- CTE based on pg_catalog to get only Primary and Foreign key columns outside api schema
|
-- CTE based on pg_catalog to get PRIMARY/FOREIGN key and UNIQUE columns outside api schema
|
||||||
*/
|
*/
|
||||||
WITH key_columns AS (
|
WITH key_columns AS (
|
||||||
SELECT
|
SELECT
|
||||||
@@ -409,7 +409,7 @@ allColumns tabs =
|
|||||||
pg_catalog.pg_class c,
|
pg_catalog.pg_class c,
|
||||||
pg_catalog.pg_namespace n
|
pg_catalog.pg_namespace n
|
||||||
WHERE
|
WHERE
|
||||||
r.contype IN ('f', 'p')
|
r.contype IN ('f', 'p', 'u')
|
||||||
AND c.relkind IN ('r', 'v', 'f', 'm')
|
AND c.relkind IN ('r', 'v', 'f', 'm')
|
||||||
AND r.conrelid = c.oid
|
AND r.conrelid = c.oid
|
||||||
AND c.relnamespace = n.oid
|
AND c.relnamespace = n.oid
|
||||||
|
|||||||
@@ -1112,3 +1112,12 @@ spec actualPgVersion = do
|
|||||||
|
|
||||||
it "cannot use ltree(in public schema) extension operators if no extra search path added" $
|
it "cannot use ltree(in public schema) extension operators if no extra search path added" $
|
||||||
get "/ltree_sample?path=cd.Top.Science.Astronomy" `shouldRespondWith` 400
|
get "/ltree_sample?path=cd.Top.Science.Astronomy" `shouldRespondWith` 400
|
||||||
|
|
||||||
|
context "VIEW that has a source FK based on a UNIQUE key" $
|
||||||
|
it "can be embedded" $
|
||||||
|
get "/referrals?select=site,link:pages(url)" `shouldRespondWith`
|
||||||
|
[json| [
|
||||||
|
{"site":"github.com", "link":{"url":"http://postgrest.org/en/v6.0/api.html"}},
|
||||||
|
{"site":"hub.docker.com", "link":{"url":"http://postgrest.org/en/v6.0/admin.html"}}
|
||||||
|
]|]
|
||||||
|
{ matchHeaders = [matchContentTypeJson] }
|
||||||
|
|||||||
@@ -231,6 +231,23 @@ spec = do
|
|||||||
]
|
]
|
||||||
|]
|
|]
|
||||||
|
|
||||||
|
describe "VIEW that has a source FK based on a UNIQUE key" $
|
||||||
|
|
||||||
|
it "includes fk description" $ do
|
||||||
|
r <- simpleBody <$> get "/"
|
||||||
|
|
||||||
|
let referralLink = r ^? key "definitions" . key "referrals" . key "properties" . key "link"
|
||||||
|
|
||||||
|
liftIO $
|
||||||
|
referralLink `shouldBe` Just
|
||||||
|
[aesonQQ|
|
||||||
|
{
|
||||||
|
"format": "integer",
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Note:\nThis is a Foreign Key to `pages.link`.<fk table='pages' column='link'/>"
|
||||||
|
}
|
||||||
|
|]
|
||||||
|
|
||||||
describe "PostgreSQL to Swagger Type Mapping" $ do
|
describe "PostgreSQL to Swagger Type Mapping" $ do
|
||||||
|
|
||||||
it "character varying to string" $ do
|
it "character varying to string" $ do
|
||||||
|
|||||||
Vendored
+8
@@ -512,3 +512,11 @@ TRUNCATE TABLE app_users CASCADE;
|
|||||||
INSERT INTO app_users (id, email, "password") VALUES (1, 'test@123.com','pass');
|
INSERT INTO app_users (id, email, "password") VALUES (1, 'test@123.com','pass');
|
||||||
INSERT INTO app_users (id, email, "password") VALUES (2, 'abc@123.com','pass');
|
INSERT INTO app_users (id, email, "password") VALUES (2, 'abc@123.com','pass');
|
||||||
INSERT INTO app_users (id, email, "password") VALUES (3, 'def@123.com','pass');
|
INSERT INTO app_users (id, email, "password") VALUES (3, 'def@123.com','pass');
|
||||||
|
|
||||||
|
TRUNCATE TABLE private.pages CASCADE;
|
||||||
|
INSERT INTO private.pages VALUES (1, 'http://postgrest.org/en/v6.0/api.html');
|
||||||
|
INSERT INTO private.pages VALUES (2, 'http://postgrest.org/en/v6.0/admin.html');
|
||||||
|
|
||||||
|
TRUNCATE TABLE private.referrals CASCADE;
|
||||||
|
INSERT INTO private.referrals VALUES ('github.com', 1);
|
||||||
|
INSERT INTO private.referrals VALUES ('hub.docker.com', 2);
|
||||||
|
|||||||
Vendored
+2
@@ -104,6 +104,8 @@ GRANT ALL ON TABLE
|
|||||||
, getallprojects_view
|
, getallprojects_view
|
||||||
, get_projects_above_view
|
, get_projects_above_view
|
||||||
, web_content
|
, web_content
|
||||||
|
, pages
|
||||||
|
, referrals
|
||||||
TO postgrest_test_anonymous;
|
TO postgrest_test_anonymous;
|
||||||
|
|
||||||
GRANT INSERT ON TABLE insertonly TO postgrest_test_anonymous;
|
GRANT INSERT ON TABLE insertonly TO postgrest_test_anonymous;
|
||||||
|
|||||||
Vendored
+14
@@ -1759,3 +1759,17 @@ create table app_users (
|
|||||||
email text unique not null,
|
email text unique not null,
|
||||||
password text not null
|
password text not null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
create table private.pages (
|
||||||
|
link int not null unique
|
||||||
|
, url text
|
||||||
|
);
|
||||||
|
|
||||||
|
create table private.referrals (
|
||||||
|
site text
|
||||||
|
, link int references private.pages(link) not null
|
||||||
|
);
|
||||||
|
|
||||||
|
create view test.pages as select * from private.pages;
|
||||||
|
|
||||||
|
create view test.referrals as select * from private.referrals;
|
||||||
|
|||||||
Reference in New Issue
Block a user