Child tables not discovered
atistler opened this issue · comments
I have a instances table that inherits from a resources table. Massive only discovers the resources table:
=> SELECT * FROM ( SELECT t.table_schema AS schema, t.table_name AS name, parent.relname AS parent, array_agg(DISTINCT kc.column_name::text) AS pk, TRUE AS is_insertable_into, array_agg(DISTINCT c.column_name::text) AS columns FROM information_schema.tables t JOIN information_schema.table_constraints tc ON tc.table_schema = t.table_schema AND tc.table_name = t.table_name JOIN information_schema.key_column_usage kc ON kc.constraint_schema = tc.table_schema AND kc.table_name = tc.table_name AND kc.constraint_name = tc.constraint_name JOIN information_schema.columns c ON c.table_schema = tc.table_schema AND c.table_name = tc.table_name JOIN pg_catalog.pg_namespace nsp ON nsp.nspname = t.table_schema JOIN pg_catalog.pg_class cls ON cls.relnamespace = nsp.oid AND cls.relname = tc.table_name LEFT OUTER JOIN pg_catalog.pg_inherits inh ON inh.inhrelid = cls.oid LEFT OUTER JOIN pg_catalog.pg_class AS parent ON inh.inhparent = parent.oid LEFT OUTER JOIN pg_catalog.pg_namespace AS parentschema ON parentschema.oid = parent.relnamespace WHERE tc.constraint_type = 'PRIMARY KEY' AND t.table_type <> 'FOREIGN TABLE' GROUP BY t.table_schema, t.table_name, parent.relname UNION SELECT t.table_schema AS schema, t.table_name AS name, NULL AS parent, NULL AS pk, CASE t.is_insertable_into WHEN 'YES' THEN TRUE ELSE FALSE END AS is_insertable_into, array_agg(c.column_name::text) AS columns FROM information_schema.tables t JOIN information_schema.columns c ON c.table_schema = t.table_schema AND c.table_name = t.table_name WHERE t.table_type = 'FOREIGN TABLE' GROUP BY t.table_schema, t.table_name, t.is_insertable_into ) tables WHERE CASE WHEN '' <> '' THEN replace((tables.schema || '.'|| tables.name), 'public.', '') LIKE ANY(string_to_array(replace('', ' ', ''), ',')) WHEN '' <> '' OR '' <> '' THEN (( '' = '' OR schema = ANY(string_to_array(replace('', ' ', ''), ',')) ) AND ( '' = '' OR replace((schema || '.'|| name), 'public.', '') NOT LIKE ALL(string_to_array(replace('', ' ', ''), ',')) )) OR replace((schema || '.'|| name), 'public.', '') LIKE ANY(string_to_array(replace('', ' ', ''), ',')) ELSE TRUE END;
schema | name | parent | pk | is_insertable_into | columns
--------+-----------+--------+------+--------------------+----------------------------------------------------------------------------------------------------
public | resources | | {id} | t | {id,properties,provider_account_id,region,resource_id,resource_type,service,source,sys_period,urn}
(1 row)
=> \d instances
Table "public.instances"
Column | Type | Modifiers
---------------------+-----------+-------------------------------------------------------------------------------
id | uuid | not null default gen_random_uuid()
provider_account_id | text | not null
service | text | not null
resource_type | text | not null
region | text | not null
source | source | not null
resource_id | text | not null
urn | text | not null
properties | jsonb | not null default '{}'::jsonb
sys_period | tstzrange | not null default tstzrange(CURRENT_TIMESTAMP, NULL::timestamp with time zone)
name | text |
ip_addresses | inet[] | not null default '{}'::inet[]
Indexes:
"instances_name_index" btree (name)
"instances_provider_account_id_index" btree (provider_account_id)
"instances_region_index" btree (region)
"instances_resource_id_index" btree (resource_id)
"instances_resource_type_index" btree (resource_type)
"instances_service_index" btree (service)
"instances_source_index" btree (source)
"instances_urn_index" btree (urn)
Inherits: resources
Number of child tables: 2 (Use \d+ to list them.)
Primary key constraints aren't inherited, and Massive looks for a primary key when it loads tables. If you add one to your instances
table it should start showing up.