diff --git a/CHANGELOG.md b/CHANGELOG.md index ca4471a397a..9f13f60f74b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ (Add entries below in the order of server, console, cli, docs, others) +- server: disable mutation for materialised views (#6688) - server: set `tracecontext` and `userInfo` for DML actions on Postgres sources - cli: add progress bar for `migrate apply` command (#4795) diff --git a/server/src-rsr/pg_table_metadata.sql b/server/src-rsr/pg_table_metadata.sql index 77affff59b5..1ce36bac426 100644 --- a/server/src-rsr/pg_table_metadata.sql +++ b/server/src-rsr/pg_table_metadata.sql @@ -10,7 +10,9 @@ SELECT -- Note: unique_constraints does NOT include primary key constraints! 'unique_constraints', coalesce(unique_constraints.info, '[]'), 'foreign_keys', coalesce(foreign_key_constraints.info, '[]'), - 'view_info', CASE "table".relkind WHEN 'v' THEN jsonb_build_object( + -- Note: for views and materialized views, we are asking Postgres if it is mutable or not + -- and for any other case, we are assuming it to be mutable. + 'view_info', CASE WHEN "table".relkind IN ('v', 'm') THEN jsonb_build_object( 'is_updatable', ((pg_catalog.pg_relation_is_updatable("table".oid, true) & 4) = 4), 'is_insertable', ((pg_catalog.pg_relation_is_updatable("table".oid, true) & 8) = 8), 'is_deletable', ((pg_catalog.pg_relation_is_updatable("table".oid, true) & 16) = 16) diff --git a/server/tests-py/queries/v1/track_table/track_untrack_materialized_view.yaml b/server/tests-py/queries/v1/track_table/track_untrack_materialized_view.yaml index 6a7484487ce..48c9de2944f 100644 --- a/server/tests-py/queries/v1/track_table/track_untrack_materialized_view.yaml +++ b/server/tests-py/queries/v1/track_table/track_untrack_materialized_view.yaml @@ -38,6 +38,40 @@ - title - name +# Introspecting the GraphQL schema for query field for the materialized view +- description: Checking query fields by introspection + url: /v1/graphql + status: 200 + response: + data: + __type: + name: "articles" + query: + query: "query checkQuery {__type(name:\"articles\"){name}}" + +# Test for checking if the mutation field doesn't exist for the materialized view +- description: Checking mutation fields for materialized view + url: /v1/graphql + status: 200 + response: + errors: + - extensions: + path: "$" + code: "validation-failed" + message: "no mutations exist" + query: + query: "mutation MyMutation { delete_articles(where: {title: {_eq: \"Lorem ipsum dolor sit amet\"}}) { affected_rows }}" + +# Introspecting the GraphQL schema for mutation fields for the materialized view +- description: Checking mutation fields by introspection + url: /v1/graphql + status: 200 + response: + data: + __type: null + query: + query: "query checkMutation {__type(name:\"articles_insert_input\"){name}}" + - description: Untrack materialized view url: /v1/query status: 200