mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 09:22:43 +03:00
console/postgres: fix broken table view when clicking on inherited tables
### Description - Fixes https://github.com/hasura/graphql-engine/issues/6926 - This is to resolve the issue where inherited tables get listed into the array that's used to filter off partitions. - In the check, we compare if the partition's parent is a "partitioned table" or not before adding to the filter array. ### Steps to verify - Create the following tables on a postgres db ```SQL CREATE TABLE cities ( id SERIAL PRIMARY KEY, name text, population real, elevation int -- (in ft) ); CREATE TABLE capitals ( state char(2) UNIQUE NOT NULL ) INHERITS (cities); ``` - Navigate to the data tab, and click on the datasource > schema, and verify that both `cities` and `capitals` are present. - Click on `capitals` and see if it loads properly. - Create the following table and its partitions ```sql CREATE TABLE measurement ( city_id int not null, logdate date not null, peaktemp int, unitsales int ) PARTITION BY RANGE (logdate); CREATE TABLE measurement_y2006m02 PARTITION OF measurement FOR VALUES FROM ('2006-02-01') TO ('2006-03-01'); CREATE TABLE measurement_y2006m03 PARTITION OF measurement FOR VALUES FROM ('2006-03-01') TO ('2006-04-01'); ``` - Verify that the data tab nav does not show `measurement_y2006m02` and `measurement_y2006m03` GitOrigin-RevId: 1cc988fff03f289e6ea36d0b1e9f8e54b8741be9
This commit is contained in:
parent
52c720a631
commit
31465c5bba
@ -65,11 +65,12 @@ export const getFetchTablesListQuery = (options: {
|
|||||||
SELECT
|
SELECT
|
||||||
COALESCE(Json_agg(Row_to_json(info)), '[]' :: json) AS tables
|
COALESCE(Json_agg(Row_to_json(info)), '[]' :: json) AS tables
|
||||||
FROM (
|
FROM (
|
||||||
with partitions as (
|
WITH partitions AS (
|
||||||
select array(
|
SELECT array(
|
||||||
|
WITH partitioned_tables AS (SELECT array(SELECT oid FROM pg_class WHERE relkind = 'p') AS parent_tables)
|
||||||
SELECT
|
SELECT
|
||||||
child.relname AS partition
|
child.relname AS partition
|
||||||
FROM pg_inherits
|
FROM partitioned_tables, pg_inherits
|
||||||
JOIN pg_class child ON pg_inherits.inhrelid = child.oid
|
JOIN pg_class child ON pg_inherits.inhrelid = child.oid
|
||||||
JOIN pg_namespace nmsp_child ON nmsp_child.oid = child.relnamespace
|
JOIN pg_namespace nmsp_child ON nmsp_child.oid = child.relnamespace
|
||||||
${generateWhereClause(
|
${generateWhereClause(
|
||||||
@ -78,18 +79,19 @@ export const getFetchTablesListQuery = (options: {
|
|||||||
'nmsp_child.nspname',
|
'nmsp_child.nspname',
|
||||||
'where'
|
'where'
|
||||||
)}
|
)}
|
||||||
) as names
|
AND pg_inherits.inhparent = ANY (partitioned_tables.parent_tables)
|
||||||
|
) AS names
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
pgn.nspname as table_schema,
|
pgn.nspname AS table_schema,
|
||||||
pgc.relname as table_name,
|
pgc.relname AS table_name,
|
||||||
case
|
CASE
|
||||||
when pgc.relkind = 'r' then 'TABLE'
|
WHEN pgc.relkind = 'r' THEN 'TABLE'
|
||||||
when pgc.relkind = 'f' then 'FOREIGN TABLE'
|
WHEN pgc.relkind = 'f' THEN 'FOREIGN TABLE'
|
||||||
when pgc.relkind = 'v' then 'VIEW'
|
WHEN pgc.relkind = 'v' THEN 'VIEW'
|
||||||
when pgc.relkind = 'm' then 'MATERIALIZED VIEW'
|
WHEN pgc.relkind = 'm' THEN 'MATERIALIZED VIEW'
|
||||||
when pgc.relkind = 'p' then 'PARTITIONED TABLE'
|
WHEN pgc.relkind = 'p' THEN 'PARTITIONED TABLE'
|
||||||
end as table_type,
|
END AS table_type,
|
||||||
obj_description(pgc.oid) AS comment,
|
obj_description(pgc.oid) AS comment,
|
||||||
COALESCE(json_agg(DISTINCT row_to_json(isc) :: jsonb || jsonb_build_object('comment', col_description(pga.attrelid, pga.attnum))) filter (WHERE isc.column_name IS NOT NULL), '[]' :: json) AS columns,
|
COALESCE(json_agg(DISTINCT row_to_json(isc) :: jsonb || jsonb_build_object('comment', col_description(pga.attrelid, pga.attnum))) filter (WHERE isc.column_name IS NOT NULL), '[]' :: json) AS columns,
|
||||||
COALESCE(json_agg(DISTINCT row_to_json(ist) :: jsonb || jsonb_build_object('comment', obj_description(pgt.oid))) filter (WHERE ist.trigger_name IS NOT NULL), '[]' :: json) AS triggers,
|
COALESCE(json_agg(DISTINCT row_to_json(ist) :: jsonb || jsonb_build_object('comment', obj_description(pgt.oid))) filter (WHERE ist.trigger_name IS NOT NULL), '[]' :: json) AS triggers,
|
||||||
|
Loading…
Reference in New Issue
Block a user