diff --git a/CHANGELOG.md b/CHANGELOG.md index e41a5ad31..c33b1619a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Added - #1099, Add support for getting json/jsonb by array index - @steve-chavez +- #1145, Add materialized view columns to OpenAPI output - @steve-chavez ### Fixed diff --git a/src/PostgREST/DbStructure.hs b/src/PostgREST/DbStructure.hs index 61cef9553..37521b3ec 100644 --- a/src/PostgREST/DbStructure.hs +++ b/src/PostgREST/DbStructure.hs @@ -388,7 +388,7 @@ allColumns tabs = pg_catalog.pg_namespace n WHERE r.contype IN ('f', 'p') - AND c.relkind IN ('r', 'v', 'f', 'mv') + AND c.relkind IN ('r', 'v', 'f', 'm') AND r.conrelid = c.oid AND c.relnamespace = n.oid AND n.nspname NOT IN ('pg_catalog', 'information_schema', $1) @@ -492,7 +492,7 @@ allColumns tabs = NOT pg_is_other_temp_schema(nc.oid) AND a.attnum > 0 AND NOT a.attisdropped - AND (c.relkind = ANY (ARRAY['r'::"char", 'v'::"char", 'f'::"char"])) + AND (c.relkind = ANY (ARRAY['r'::"char", 'v'::"char", 'f'::"char", 'm'::"char"])) AND (nc.nspname = $1 OR kc.r_oid IS NOT NULL) /*--filter only columns that are FK/PK or in the api schema */ /*--AND (pg_has_role(c.relowner, 'USAGE'::text) OR has_column_privilege(c.oid, a.attnum, 'SELECT, INSERT, UPDATE, REFERENCES'::text))*/ ) diff --git a/test/Feature/StructureSpec.hs b/test/Feature/StructureSpec.hs index a8c472148..435e0686f 100644 --- a/test/Feature/StructureSpec.hs +++ b/test/Feature/StructureSpec.hs @@ -163,6 +163,38 @@ spec = do ] |] + describe "Materialized view" $ + + it "includes materialized view properties" $ do + r <- simpleBody <$> get "/" + + let method s = key "paths" . key "/materialized_projects" . key s + summary = r ^? method "get" . key "summary" + description = r ^? method "get" . key "description" + parameters = r ^? method "get" . key "parameters" + + liftIO $ do + + summary `shouldBe` Just "A materialized view for projects" + + description `shouldBe` Just "Just a test for materialized views" + + parameters `shouldBe` Just + [aesonQQ| + [ + { "$ref": "#/parameters/rowFilter.materialized_projects.id" }, + { "$ref": "#/parameters/rowFilter.materialized_projects.name" }, + { "$ref": "#/parameters/rowFilter.materialized_projects.client_id" }, + { "$ref": "#/parameters/select" }, + { "$ref": "#/parameters/order" }, + { "$ref": "#/parameters/range" }, + { "$ref": "#/parameters/rangeUnit" }, + { "$ref": "#/parameters/offset" }, + { "$ref": "#/parameters/limit" }, + { "$ref": "#/parameters/preferCount" } + ] + |] + describe "RPC" $ do it "includes body schema for arguments" $ do diff --git a/test/fixtures/privileges.sql b/test/fixtures/privileges.sql index 38440dbce..5b2078b5b 100644 --- a/test/fixtures/privileges.sql +++ b/test/fixtures/privileges.sql @@ -86,6 +86,7 @@ GRANT ALL ON TABLE , authors_have_book_in_decade , foos , bars + , materialized_projects TO postgrest_test_anonymous; GRANT INSERT ON TABLE insertonly TO postgrest_test_anonymous; diff --git a/test/fixtures/schema.sql b/test/fixtures/schema.sql index e4af1a68d..33715f2c6 100755 --- a/test/fixtures/schema.sql +++ b/test/fixtures/schema.sql @@ -1536,3 +1536,11 @@ CREATE TABLE test.bar( CREATE VIEW test.foos as select id,name from "Foo"; CREATE VIEW test.bars as select id, "fooId", name from bar; + +create materialized view materialized_projects as +select id, name, client_id from projects; + +comment on materialized view materialized_projects is +$$A materialized view for projects + +Just a test for materialized views$$;